0
這是我啓動我的應用程序的主要方法。 JFrame加載成功。當我添加WHILE循環部分做一些後臺工作,我的一些數據顯示在我的JFrame上顯示我的JFrame無法正確加載(見下圖)。循環後的Java JFrame加載錯誤
public static void main(String[] args) throws IOException {
if (Config.checkIfConfigExists() == true) {
/*
* Starten der Anwendung
*/
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main window = new Main();
window.frmServicenowHelper.invalidate();
window.frmServicenowHelper.validate();
window.frmServicenowHelper.repaint();
window.frmServicenowHelper.setVisible(true);
while (true) {
// the part that makes it error
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
} else {
Notifications.alertMSGConfig("Config not found. Create one?");
}
}
正如你所看到的JFrame凍結並顯示其背景。
我發現它是與Threads
和正確處理(我想我使用的東西在錯誤的點),但我不能要自己解決。
背景知識:
我想從一個URL的JSON字符串(該方法的工作 - 我想打電話給&顯示框上的結果),每5分鐘(因此而環)。
編輯:
我嘗試這樣做,其正確地加載幀而是使得環(我需要)沒用:
while (true) {
Main window = new Main();
window.frmServicenowHelper.invalidate();
window.frmServicenowHelper.validate();
window.frmServicenowHelper.repaint();
window.frmServicenowHelper.setVisible(true);
break;
}
你在重新粉刷之前睡了一段時間嗎?您確定多個線程不在JFrame上運行嗎? –
@AlexBaranowski我在任何時候都沒有睡覺 - 我很確定它只有一個線程。添加** break; **使其工作,但使循環無用,我需要 – piguy