我导入javax.swing.*;
并拥有一个JOptionPane:
String meny = JOptionPane.showInputDialog(null, "What's the answer?").trim();
我希望在用户插入的秒数后关闭此窗口:
String time = JOptionPane.showInputDialog(null, "How much time").trim();
int timer1 = Integer.parseInt(time);
我不知道该怎么做。我应该这样做吗?
if (timer1 == 0) {
meny.setVisible(false);
}
提前致谢!
答案 0 :(得分:0)
试试这段代码:
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();