Showing Date and Ticking Time Dynamically on a Frame! Very Urgent!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   King_Arvind
Posted On:   Thursday, April 19, 2001 03:13 AM

How do I display the ticking time in a Frame's status Bar..
?


Thank you in Advance,

lOving,
Arvind.

Re: Showing Date and Ticking Time Dynamically on a Frame! Very Urgent!

Posted By:   Robert_Roy  
Posted On:   Monday, April 23, 2001 10:49 AM

Create a 1000 millisecond timer that gets the current date and time then format them and write them out to the status bar.

Sample code:

timer = new Timer( ONE_SECOND, new ActionListener()
{
public void actionPerformed( ActionEvent evt )
{
Date date = new Date();
if ( date != oldDate )
{
// Only update when date changes
String strDate = DateFormat.getDateInstance().format( date );
*** code to write strDate to status bar ***
oldDate = date;
}

String strTime = DateFormat.getTimeInstance().format( date );
*** code to write strTime to status bar ***
}
} );

// Start the timer
timer.start();

// Add a finalize method to stop the timer when the app is terminated
protected void finalize()
{
timer.stop();
}
About | Sitemap | Contact