Here is the code I’m using.
public class timerApp {
Runnable timerRun = new runX();
Thread thread1 = new Thread(timerRun);
public static void main(String[] args) {
timerApp xyz = new timerApp();
xyz.createGUI();
}
public void createGUI() {
JButton button = new JButton("Start timer");
JButton button2 = new JButton("Stop timer");
JFrame frame = new JFrame();
JLabel label = new JLabel("under_construction");
frame.getContentPane().add(BorderLayout.NORTH,button);
frame.getContentPane().add(BorderLayout.SOUTH,button2);
frame.getContentPane().add(BorderLayout.CENTER,label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setVisible(true);
button.addActionListener(new b1L());
button2.addActionListener(new b2L());
}
public class b1L implements ActionListener {
public void actionPerformed(ActionEvent event) {
thread1.start();
}
}
public class b2L implements ActionListener {
public void actionPerformed(ActionEvent event) {
thread1.stop();
}
}
}
I get an error Note: timerApp.java uses or overrides a deprecated API. Note: Recompile with Xlint:deprecation for details.
I started getting this after adding the stop button’s listener class.
RELP!
You get this warning as Thread’s stop() method is deprecated.
Why is Thread.stop deprecated?
Nice link:
http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html
This link provides info related to your question for :
Thread.stop?
long periods (e.g., for input)?
Thread.interrupt?
Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated?