[英]Java: How to put timer in JOptionPane that's imported?
I import javax.swing.*;
我导入javax.swing.*;
and have a JOptionPane: 并有一个JOptionPane:
String meny = JOptionPane.showInputDialog(null, "What's the answer?").trim();
I want this window to close after the amount of seconds the user inserts: 我希望在用户插入的秒数后关闭此窗口:
String time = JOptionPane.showInputDialog(null, "How much time").trim();
int timer1 = Integer.parseInt(time);
I do not know how to do this. 我不知道该怎么做。 Should I do something like this? 我应该做这样的事情吗?
if (timer1 == 0) {
meny.setVisible(false);
}
Thanks in advance! 提前致谢!
Try this code: 试试这个代码:
JOptionPane pane = new JOptionPane("Message", JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = pane.createDialog(null, "Title");
dialog.setModal(false);
dialog.setVisible(true);
new Timer(10000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
}
}).start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.