Javax Swing Timer Help

Posted by kap on Stack Overflow See other posts from Stack Overflow or by kap
Published on 2010-04-12T12:44:51Z Indexed on 2010/04/12 12:53 UTC
Read the original article Hit count: 321

Filed under:

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.

© Stack Overflow or respective owner

Related posts about java