code:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea_output.append(new Date() + ": start\n");
try {
Thread.sleep(5000);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
textArea_output.append(new Date() + ": end");
}
});
output:
Sat Nov 30 14:46:08 CST 2013: start
Sat Nov 30 14:46:13 CST 2013: end
The problem is that the two outputs appear at the same time. And what I want is, the first one, 5 seconds, then another.
I tried several ways to solve it but all failed. The button just froze the whole frame, even the textArea won't update its content during the time.
This page helps. Just Simply starts a new Thread. (I tried this but I don't know why it didn't work that time.