Hi everybody,
my problem is as follow, I have two classes myClass and myGUI
myClass code is
public class MyClass
{
public void start()
{
while (true)
{
// do some stuff
}
}
public void stop()
{
System.out.println("Hello from stop method!");
}
}
myGUI code is
public class MyGUI extends javax.swing.JFrame
{
MyClass cl = new MyClass();
public static void main(String[] args)
{
MyGUI inst = new MyGUI();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public MyGUI()
{
super();
initGUI();
}
private void initGUI()
{
// some GUI code
myStartBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
cl.start();
}
});
myStopBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
cl.stop();
}
});
}
}
as you can see, the start() method puts the program in an infinite loop, which makes me unable to call the stop() method using myStopBtn... So, I think this can be done using threads but actually I don't know how exactly am gonna do this
any help will be appreciated.
Thanks