In the past few months I've tried my hand at programming in Java, and for the most part haven't had any problems with it, but right now I'm having some trouble working with voids. In my program the user presses a button and the goal is for multiple messages to be displayed on a JLabel, the messages spread out with a Thread.sleep() method. For some reason only the last one ends up being sent. Here's my code. It's not all of it, but I'm pretty sure that the problem is somewhere in here. The error outputs in there were to try and see what was going on in the code, but, obviously they didn't end up working.
private class ClickListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
if (e.getSource() == exitButton)
System.exit(0);
else if (e.getSource() == button1)
alValue = "This is the new message text.";
System.err.println(alValue);
createNewArrayList();
Thread.sleep(3000);
alValue = "Back to invisible...";
System.err.println(alValue);
createNewArrayList();
Thread.sleep(2000);
alValue = "";
System.err.println(alValue);
createNewArrayList();
} catch (InterruptedException ex) {
Logger.getLogger(EmptySpace.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
and
private void createNewArrayList() {
ArrayList al = new ArrayList();
al.add(alValue);
label1.setText("" + al);
}