首頁  >  文章  >  Java  >  如何使用沒有按鈕的計時器從另一個 JFrame 呼叫一個 JFrame?

如何使用沒有按鈕的計時器從另一個 JFrame 呼叫一個 JFrame?

DDD
DDD原創
2024-10-26 10:13:03144瀏覽

How to Call One JFrame from Another with a Timer Without Buttons?

使用不含按鈕的計時器從另一個JFrame 呼叫一個JFrame

問題:

您對從以下位置呼叫一個JFrame 感到困惑另一種方法是在NetBeans 中使用沒有任何按鈕的計時器。能提供一下解決方案嗎?

答案:

您的問題不夠清晰,但一般不建議使用多個框架。或者,您可以使用如下所示的無模式對話框:

Java 程式碼:

<code class="java">import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.Timer;

/**
 * @see https://stackoverflow.com/a/12451673/230513
 */

public class JOptionTimeTest implements ActionListener, PropertyChangeListener {

    // Constants
    private static final int TIME_OUT = 10;

    // Instance Variables
    private int count = TIME_OUT;
    private final Timer timer = new Timer(1000, this);
    private JDialog dialog = new JDialog();
    private final JOptionPane optPane = new JOptionPane();

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                new JOptionTimeTest().createGUI();
            }
        });
    }

    private void createGUI() {
        // Create a JFrame</code>

以上是如何使用沒有按鈕的計時器從另一個 JFrame 呼叫一個 JFrame?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn