生成一段java代码, 这段代码创建了一个定时器,在定时器每隔一分钟的时候会执行一次任务,任务内容是创建一个新的线程并弹出一个消息框,然后线程会休眠3秒钟,最后关闭消息框
时间: 2023-05-30 19:04:30 浏览: 106
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TimerTask {
public static void main(String[] args) {
Timer timer = new Timer(60000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(null, "This is a message");
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
JOptionPane.getRootFrame().dispose();
}
});
thread.start();
}
});
timer.start();
}
}
阅读全文