Hi
I want to do a sequential event chain in a
Java Gui application.
As an example iIwant to change the name of a button after every second, so here it is: first wait a second then change name in "cat", then wait a minute and change name into "get".
The method um() should do this.
The strange thing is:
If i start um() from method set(), everything works fine .
If i start um() from the action performed method, it first does the waiting, and then the name gets directly to get.
Heres the code:
import java.awt.event.*;
import javax.swing.*;
public class pauser implements ActionListener {
JFrame frame = new JFrame();
JButton button = new JButton("hat");
public void set(){
frame.setSize(401,400);
frame.setVisible(true);
frame.add(button);
button.setEnabled(true);
button.addActionListener(this);
frame.setVisible(true);
um();
}
public void actionPerformed(ActionEvent event){
um();
}
void um(){
try{Thread.sleep(1000);}catch(Exception e1){}
button.setText("cat");
try{Thread.sleep(1000);}catch(Exception e1){}
button.setText("get");
}
public static void main(
String[] args) {
new pauser().set();
}
}
Anyone who could help me out