這是我正在使用的代碼。無法停止線程
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