Stop a timer in other class
Heey all!
I'm trying to stop a timer with a button, and the timer is in a other class. How to fix it? (Timer is public)
Verblijf.java:
Code:
public Verblijf()
{
booleanGenerator = new Random();
random = new Random();
addMouseListener(this);
willekeurigDier();
timer = new Timer(150, this);
timer.start();
timer2 = new Timer(2000, this);
timer2.start();
}
Now I want to stop the timer from the class 'Knoppenbalk.java'. I've tried:
Code:
public Verblijf verblijf = new Verblijf();
(...)
knop1 = new JButton("Knop1 ");
knop1.addActionListener(this);
add(knop1);
(...)
public void actionPerformed(ActionEvent e)
{
verblijf.timer.stop();
}
Thanks in advance!