After advice from another thread, I've been playing with the timer class without much joy. Heres my code:
public void buttonImageReveal(ActionEvent e){
Timer gameTimer = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
}
});
String temp = e.getActionCommand();
switch(temp){
case "1":
System.out.println("case1");
((JButton)e.getSource()).setIcon(one);
gameTimer.start();
((JButton)e.getSource()).setIcon(null);
break;
All I want is a 1 second gap between the image one been shown as the icon then that been removed. Only to happen once when the button is click. At the moment I just get a blank button when pressed?
TIA
Edit:
public void actionPerformed(ActionEvent e) {
System.out.println(e);
lastImage();
}
});
public void buttonImageReveal(ActionEvent e){
String temp = e.getActionCommand();
switch(temp){
case "1":
((JButton)e.getSource()).setIcon(one);
lastBtn = ((JButton)e.getSource());
gameTimer.start();
break;
It now doing what it should, but the timer keeps going and going, what do you do to once your finished and want it to stop?!