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();
}