I am having trouble running javax.swing.Timer after a mouse click. I want to start a timer to perform some animation after the user clicks on the button, but it does not work.
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());
}
private class MoveListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
}
This is the class that contains the button, so when the user clicks on the button, the timer starts to start the animation
public class Test{
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.btnConnect){
ShowMe vis = new ShowMe();
vis.getTimer().start();
}
}
}
I want to start the timer to start the animation, but it does not work.
Need help on how to start a timer after pressing a button.
Thank.
source
share