Home  >  Article  >  Java  >  How to Call One JFrame from Another with a Timer Without Buttons?

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

DDD
DDDOriginal
2024-10-26 10:13:03144browse

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

Calling One JFrame from Another Using Timer without Buttons

Question:

You're confused about calling one JFrame from another using a timer without any buttons in NetBeans. Can you provide a solution?

Answer:

Your question lacks clarity, but it's generally not recommended to use multiple frames. Alternatively, you can use a modeless dialog like the one demonstrated below:

Java Code:

<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>

The above is the detailed content of How to Call One JFrame from Another with a Timer Without Buttons?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn