Javax Swing Timer Help
- by kap
Hello Guys,
I am having some problems concerning starting javax.swing.Timer after a mouse click. I want to start the timer to perform some animation after the user clicks on a button but it is not working.
Here are the code snippets:
public class ShowMe extends JPanel{
private javax.swing.Timer timer;
public ShowMe(){
timer = new javax.swing.Timer(20, new MoveListener());
}
// getters and setters here
private class MoveListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// some code here to perform the animation
}
}
}
This is the class which contains a button so that when the user clicks on the button the timer starts to begin the animation
public class Test{
// button declarations go here and registering listeners also here
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.btnConnect){
ShowMe vis = new ShowMe();
vis.getTimer().start();
}
}
}
I want to start the timer to begin the animation but it is not working.
Need help how to make a timer start after button click.
Thanks.