Big Data and Hadoop Training @$80 or Rs. 6,000 only - valid till Oct 17th Apply Now!

Set delay time in JOptionPane

Ads
 

Set delay time in JOptionPane

Learn how to use 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" ));
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:

 

Ads

Ads