Monday, July 27, 2009

Java code to make a message box appear after a timed delay?

I want to be able to customize what the box says; put "Happy birthday!" into it so I know where the text is. I want to run the java program, then have the alert box pop up after a minute (customizable amount of time would be preferred). I am planning on having this be a practical joke, so can you please make the alert box look as windows-like as possible?








please write the java code in your answer. I am dying to see this work. thank you so much!

Java code to make a message box appear after a timed delay?
import javax.swing.JOptionPane;


import javax.swing.UIManager;


import javax.swing.UnsupportedLookAndFeelExcept...








public class Test{


public static void main(String args[])


{


try {





UIManager.setLookAndFeel(


UIManager. getSystemLookAndFeelClassName () );


}


catch ( UnsupportedLookAndFeelException e ) {


// handle exception


}


catch (ClassNotFoundException e) {


// handle exception


}


catch (InstantiationException e) {


// handle exception


}


catch (IllegalAccessException e) {


// handle exception


}


int time = 0;


while(true) {


try


{


time = Integer.parseInt( JOptionPane.showInputDialog ( "Enter time in second" ));


break;


} catch (NumberFormatException e)


{


JOptionPane.showMessageDialog( null, "Invalid" );


}


}


time *=1000;


String str = JOptionPane.showInputDialog( "Enter your message" );


if (str == null) return;


while(true)


{


try {


Thread.sleep(time);


JOptionPane.showMessageDialog( null,str,"Alert", JOptionPane.ERROR_MESSAGE);


} catch (InterruptedException e) {


// TODO Auto-generated catch block


e.printStackTrace();


}


}


}


}








Ok dont make people get annoyed with your joke.





Note that this program will repeatedly pop up the message until you stop it.
Reply:Does not look easy. May be you can contact a java expert at websites like


http://designquot.net/
Reply:import java.util.*;





class HappyBday{


public static void main(String args[]){


Calendar when= Calendar.getInstance(), now= Calendar.getInstance();


when.set(/*int year, int month, int date, int hour, int minute, int second*/)//you set this up


do{


now.setTime( Calendar.getInstance(). getTime() );


}while( when.getTime().getTime() %26gt; now.getTime().getTime() );


JOptionPane.showMesageDialog( null, "Happy BirthDay!" );


}


}


//maybe this will work.


No comments:

Post a Comment