这是我正在使用的代码。无法停止线程
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();
}
}
}
我得到一个错误Note: timerApp.java uses or overrides a deprecated API. Note: Recompile with Xlint:deprecation for details.
我开始加入了停止按钮的监听器类后得到这个。
RELP!
+1表示使用什么来代替'thread.stop()' – 2010-08-21 12:54:56