I have a window that has various panels. On one panel, I have a JTextArea called dogTalk where I update its text. Upon user's click of a button, I want the text to add what I have mentioned below in setText.
I used the sleep method so that the user can read my updated text and the window can close automatically within 4 seconds. (I don't want the user to have the ability to close the window on close, hence I didn't use Jframe.EXIT_ON_CLOSE but used JFrame.DO_NOTHING_ON_CLOSE and used my automatic closing with the help of sleep and system.ext(0))
However, I noticed that the sleep method does not allow the dogTalk to get updated. It prints out "we're working", though, so I am guessing it's a problem with the window? I know that the sleep is causing the issue and not something else in my code because when I commented out the sleep and system.exit(0) and tested if my if statement is executing, I noticed the JTextArea did update with my statement just fine! Could you please help me?
if (e.getActionCommand().equals("buybone")) {
System.out.println("We're working");
dogTalk.setText(dogTalk.getText() + "\nWow bone very wow much thanks bye.");
try
{
TimeUnit.SECONDS.sleep(4);
}
catch ( InterruptedException e1 )
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.exit(0);
}