Home > Java > javaTutorial > 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
Release: 2024-10-26 10:13:03
Original
276 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template