簡體   English   中英

Java:如何將計時器放在導入的JOptionPane中?

[英]Java: How to put timer in JOptionPane that's imported?

我導入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);
}

提前致謝!

試試這個代碼:

            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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM