This is my main method where I start my application. The JFrame loads successfully. When I add the WHILE-Loop part to do some background work where I work with some data to show on my JFrame my JFrame doesn't load correctly (see image below).
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?");
}
}
As you can see the JFrame freezes and shows its background.
I found out it has something to do with Threads
and correct processing (I think I am using something at the wrong point) but I am unable to fix it myself.
Background knowledge:
I want to get a JSON-String from a URL (the methods for that are working - I want to call & show the results on the frame) every 5 minutes (therefore the while-loop).
EDIT:
I tried this which loads the frame correctly but makes the loop (which I need) useless:
while (true) {
Main window = new Main();
window.frmServicenowHelper.invalidate();
window.frmServicenowHelper.validate();
window.frmServicenowHelper.repaint();
window.frmServicenowHelper.setVisible(true);
break;
}