I read this in an online sources:
setVisible(true)
side-effect: Even if you didn't initialize the GUI on the EDT, a side-effect of callingsetVisible(true)
is to start the EDT thread, which continues to run and monitor the GUI.
If this is true, what is the effect of setVisible(false)
on the EDT?
theButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println("Test 1");
System.out.println("Still Testing");
panel.remove(theButton);
panel.revalidate();
panel.repaint();
myFrame.dispose();
dothis();
myFrame.setVisible(true);
}});
Function dothis()
:
public void dothis()
{
for (int i=0;i<9999999999;i++)
{
System.out.println("Test 1"+i);
}
}
I am aware that actionPerformed()
runs in the Event Dispatch thread.But in the above program,the JFrame reappears before actionPerformed()
is completely executed (since dothis()
is still printing),why is this happening?
Does
myFrame.setVisible()
run in a different thread?-Why isn't it following the event queue in this case?
-If
myFrame.setVisible
initiates the EDT as said in the above statement I have added,what doesmyFrame.dispose()
do?
I have posted similar questions before but I come up with more problems as I practise and I am not able to find online solutions for many of these.
- Another problem which makes me believe
myFrame.setVisible()
runs in a different thread than EDT is thatthe frame reappears but the button is not removed yet
.It reappears with the button in it and it reappears beforeactionPerformed()
is completely executed. - I am also using the Eclipse Console,the
dothis()
is displaying stuff on the console,so I thinkdothis()
must be running on a different thread than the EDT.Is this right?
Can someone give me a detailed explanation about this.Long answers are appreciated too.I couldn't find any specific issue related to my problem on the internet.Please help me.