Basically this code gets called from a JButton(in another class) to move the cube by repainting it over and over again. I wish to create another JButton to stop the timer (timer.stop()) from another method. How would i do that
private ActionListener actionListener ;
public void moveCube()
{
actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
cube.moveBox(7,5);
repaint();
}
};
Timer timer = new Timer( 100, actionListener );
timer.start();
}