Chr*_*Geo 5 java swing camera timer jframe
我有一个特定的任务,我按计划的时间间隔运行。基本上,我在 JFrame 中的标签上显示相机提要。但是,当我退出 JFrame 时,应用程序似乎在运行。我怎样才能阻止它?我已经剥离了代码的细节,只留下了相关的部分
public class TaskCLass extends JFrame {
JPanel p;
JLabel l;
Timer timer;
public TaskCLass() {
p = new JPanel();
l = new JLabel("Window");
add(p);
p.add(l);
setSize(700, 600);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.out.println(e);
timer.purge();
timer.cancel();
System.exit(1);
}
public void windowClosed(WindowEvent e) {
System.out.println(e);
timer.purge();
timer.cancel();
System.exit(1);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
startTask();
}
public static void main(String[] args) {
new TaskCLass();
}
public void startTask() {
TimerTask t = new TimerTask() {
@Override
public void run() {
//.........
}
};
timer = new Timer();
timer.schedule(t, 0, 200);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1645 次 |
| 最近记录: |