1
我試圖讓我的main
班級從另一個班級獲得alertText
的內容,該班級使用Jsoup
來抄襲網站。報廢工作正常,我只是無法得到alertText
變量不錯。我試圖讓AlertSystemDaemon
班的主班級負責填寫JLabel jLabelAlertSystem
的內容。 我嘗試過使用jLabelAlertSystem.setText(String.valueOf(alertText));
試圖從另一個班級獲得變數
但是這將會像以前一樣在alertText
上出錯。
主類:
public static void main(String[] args) {
MainPanel mainPanel = new MainPanel();
mainPanel.initialize();
mainPanel.frame.setVisible(true);
systemTray();
}
private void initialize() {
SplashScreen splash = new SplashScreen(3000);
splash.showSplash();
AlertSystemDaemon alertsystemdaemonobject = new AlertSystemDaemon();
try {
alertsystemdaemonobject.alertSystemMessage();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
frame = new JFrame();
frame.setTitle(Label.MAIN_PANEL);
frame.setBounds(100, 100, 1140, 768);//
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel jLabelAlertSystem = new JLabel(alertText, SwingConstants.RIGHT);
jLabelAlertSystem.setBounds(750, 0, 360, 20);
jLabelAlertSystem.setFont(new Font("Calibri", Font.BOLD, 15));
jLabelAlertSystem.setForeground (Color.red);
jLabelAlertSystem.setText(String.valueOf(alertText));
frame.getContentPane().add(jLabelAlertSystem);
其他類:
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class AlertSystemDaemon {
public void alertSystemMessage() throws IOException {
//MainPanel mainpanel = new MainPanel();
String url = "http://example.com/alertpage";
Document document = Jsoup.connect(url).get();
String alertText = document.select("p").first().text();
// jLabelAlertSystem.setText(String.valueOf(alertText));
System.out.println(alertText);
}
}
太謝謝你了! – javajoejuan