Reputation: 653
I have a GUI class that works fine, however I have a button in that GUI class that is the supposed to open a new GUI from another class..
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
GUI2 newGui = new GUI2();
newGui.setVisible(true);
}
However, when the new GUI class (newGui) is called, it just appears as a see-through window. Is this becuase both GUI's can't run at the same time?
I'm now trying to open the new GUI as a thread, but I don't know how to do this!
Thread thread = new Thread();
thread.sleep(5000);
thread.newGui.setVisible();
public void run();
This was my attempt, but unsurprisingly this didn't work.
Any help?
Thanks!
Upvotes: 2
Views: 79
Reputation:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
Thread thread = new Thread(){
public void run(){
GUI2 newGui = new GUI2();
newGui.setVisible(true);
}
};
thread.start();
}
Upvotes: 0
Reputation: 2516
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
GUI2 newGui = new GUI2();
newGui.setVisible(true);
}
});
Upvotes: 3