- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to display Frame after some seconds
Use Timer() to set seconds for delay i.e. to display frame after a few seconds −
Timer tm = new Timer(2000, new ActionListener() { // }
The following is an example to display Frame after some seconds −
package my; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.Timer; public class SwingDemo extends JFrame { private JFrame frame = new JFrame(); public SwingDemo() { frame.setSize(550, 300); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setVisible(true); frame.setExtendedState(JFrame.ICONIFIED); Timer tm = new Timer(2000, new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { frame.setExtendedState(JFrame.NORMAL); } }); } }); tm.setRepeats(false); tm.start(); } public static void main(String[] args) { new SwingDemo(); } }
The output is as follows displaying that the Frame appears after 2 seconds −
Output
- Related Articles
- Display seconds with SimpleDateFormat(“s”) in Java
- Java Program to create Duration from seconds
- Display seconds with SimpleDateFormat('ss') in Java
- Display Seconds in ss format (01, 02) in Java
- Java Program to get Epoch seconds from Instant
- Java Program to get Milli seconds from Instant
- Java Program to minus seconds and nanoseconds from Instant
- Java program to display English alphabets
- Java Program to display printable characters
- Java Program to Display Fibonacci Series
- Program to find mean of array after removing some elements in Python
- Display multiple components in an Internal Frame in Java
- Java Program to display upper triangular matrix
- Display seconds since the epoch with Java Date and Time Conversion Character
- Java Program to get the seconds since the beginning of the Java epoch

Advertisements