Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Set delay time in JOptionPane

Learn how to use set delay time in JOptionPane.

Ads

Tutorials   
Ads

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:

 

Advertisements

Ads
Share on Google+Share on Google+

Set delay time in JOptionPane

Posted on: October 15, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Set delay time in JOptionPane  

Post your Comment


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

Ads

 

Ads