FAQs
Search
Recent Topics
Flagged Topics
Hot Topics
Best Topics
Register / Login
Win a copy of
Securing DevOps
this week in the
Security
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Liutauras Vilda
Bear Bibeault
Devaka Cooray
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Campbell Ritchie
Henry Wong
Saloon Keepers:
Tim Moores
Ron McLeod
salvin francis
Stephan van Hulst
Vijitha Kumara
Bartenders:
Tim Holloway
Carey Brown
Frits Walraven
Forum:
Swing / AWT / SWT
Display of time and date in status bar
Huang Crystal
Greenhorn
Posts: 20
posted 16 years ago
Hi all, can anyone tell me how to display the time and date in the status bar using swing?
Advice on the implementation on the status bar is need too.
thanx in advance...
0=),<BR>Crystal
Manfred Leonhardt
Ranch Hand
Posts: 1492
posted 16 years ago
Hi Huang,
You mean something like the following.
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.text.*; public class TimeFrame extends JFrame implements ActionListener { JLabel label; SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" ); public TimeFrame() { super( "Time Frame" ); setSize( 500, 500 ); label = new JLabel( sdf.format( new GregorianCalendar().getTime() ) ); label.setHorizontalAlignment( JLabel.RIGHT ); Container cont = getContentPane(); cont.add( label, BorderLayout.SOUTH ); Timer timer = new Timer( 1000, this ); timer.start(); } public void actionPerformed( ActionEvent ae ) { label.setText( sdf.format( new GregorianCalendar().getTime() ) ); } public static void main(String[] args) { TimeFrame tf = new TimeFrame(); tf.setVisible( true ); } }
Enjoy,
Manfred.
Post Reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
regarding the status bar
Status Bar
Displaying errors in a GUI
Java Timer & Clock
regarding the status bar
More...