Home Java Example Java Swing Set delay time in JOptionPane



Set delay time in JOptionPane
Posted on: October 15, 2009 at 12:00 AM
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" ));
break;
}
time *=1000;
String str = JOptionPane.showInputDialog"Enter your message" );
if (str == nullreturn;
try {
Thread.sleep(time);
JOptionPane.showMessageDialognull,str,"Alert", JOptionPane.ERROR_MESSAGE);
catch (Exception e) {}
}
}

Download Source Code:

 

Related Tags for Set delay time in JOptionPane:
ctimeiouserdisplayusingthismessagesetpromptfortolearnoptionldsheareilsectionspluseulimfirstenterinmjoptionpanentplaysagejispafteresallagemehowpropanwhichsssaspesspaneisirimelleaandarsasecondsssthshocondstafdispplprndonomonp


More Tutorials from this section

Ask Questions?    Discuss: Set delay time in JOptionPane  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.