Java:如何将计时器放在';什么是进口的?

Java:如何将计时器放在';什么是进口的?,java,swing,timer,joptionpane,Java,Swing,Timer,Joptionpane,我导入javax.swing.*并具有作业窗格: String meny = JOptionPane.showInputDialog(null, "What's the answer?").trim(); 我希望此窗口在用户插入的秒数后关闭: String time = JOptionPane.showInputDialog(null, "How much time").trim(); int timer1 = Integer.parseInt(time); 我不知道怎么做。我应该这样做吗

我导入
javax.swing.*并具有作业窗格:

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);
}
提前谢谢

请尝试以下代码:

            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();
这很“复杂”,看看吧