Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java Example Java Swing Set delay time in JOptionPane

Related Tutorials


Share on Google+Share on Google+

Set delay time in JOptionPane

Learn how to use set delay time in JOptionPane.

Set delay time in JOptionPane


In this section, you will learn how to set the time after which the message should be displayed using JOptionpane. For this, first of all we prompt the user to enter time in seconds and the message to display. After that using the Thread.sleep() method we have allowed the message to be displayed after the specific interval of time.

Here is the code:

import javax.swing.*;

public class SetDelayTime{
public static void main(String args[]){
try {

UIManager.setLookAndFeel(UIManager. getSystemLookAndFeelClassName () );
catch Exception e ) {}
int time = 0;
while(true) {
time = Integer.parseIntJOptionPane.showInputDialog "Enter time in seconds" ));
time *=1000;
String str = JOptionPane.showInputDialog"Enter your message" );
if (str == nullreturn;
try {
JOptionPane.showMessageDialognull,str,"Alert", JOptionPane.ERROR_MESSAGE);
catch (Exception e) {}

Download Source Code:



If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 15, 2009

Related Tutorials

Discuss: Set delay time in JOptionPane  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image