setIcon on JButton then Thread.sleep then setIcon to null but it not work
I want to do step like this.
When click on JButton, set Icon to such JButton,
then delay for awhile says, 1 second.
Then remove Icon from JButton.
My demo code is below, but when I did it,
JButton doesn't show icon at all.
It goes like after click, program pauses, then nothing shows on JButton
What else can I do to do this?
Thank you very much..
=========== domo code ============
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Demo extends JFrame implements ActionListener {
ImageIcon icon = new ImageIcon("sprites/0.png");
JButton b = new JButton("Click");
Demo(){
b.addActionListener(this);
add(b);
this.setSize(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
b.setIcon(icon);
try {Thread.sleep(1000);} catch (InterruptedException e1) {}
b.setIcon(null);
}
public static void main(String[] args) {
new Demo();
}
}

