import javax.swing.JOptionPane;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Test {
public static void main(String[] args) {
// 设置延时自动关闭的时间(单位:毫秒)
int delayInMillis = 3000;
System.out.println("test");
Timer timer = new Timer(delayInMillis, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("test");
// 关闭弹出框
JOptionPane.getRootFrame().dispose();
}
});
timer.setRepeats(false); // 只触发一次
timer.start();
// 显示弹出框
JOptionPane.showMessageDialog(null, "这是一个弹出提示框");
}
}
在JAVA如何让JOptionPane.showMessageDialog()过3秒自动关闭
最新推荐文章于 2024-05-15 17:16:59 发布