This week's book giveaway is in the
Agile and other Processes
forum.
We're giving away four copies of
The Mikado Method
and have Ola Ellnestam and Daniel Brolund on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
How do I get a current date and time in a JLabel?
Aaron Parker
Greenhorn
Joined: Jan 31, 2004
Posts: 27
posted
Mar 21, 2004 12:48:00
0
I can't get this to compile. How do I get a date into the label?
import java.util.*; import java.awt.*; import java.awt.event.*; import java.text.*; import javax.swing.*; /** * Description of the Class * *@author Aaron *@since March 10, 2004 */ public class TodayIs extends JApplet implements ActionListener { Container con = getContentPane(); FlowLayout f = new FlowLayout(); JButton button1 = new JButton(); JLabel todayIs = new JLabel("Today is "); JLabel dateTime = new JLabel(dateAndTime); /** Description of the Method */ public void init() { con.setLayout(f); con.add(button1); button1.addActionListener(this); button1.requestFocus(); } /** * Description of the Method * *@param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { con.add(dateTime); validate(); } }
Aaron Parker
Greenhorn
Joined: Jan 31, 2004
Posts: 27
posted
Mar 21, 2004 12:50:00
0
(Before I had Date dateAndTime = new Date(); just above
JLabel
dateTime)
Carlos Failde
Ranch Hand
Joined: Oct 20, 2000
Posts: 84
posted
Mar 21, 2004 14:36:00
0
Howdy.
Date dateAndTime = Calendar.getInstance().getTime();
JLabel
dateTime = new
JLabel
(dateAndTime.toString());
I agree. Here's the link:
http://aspose.com/file-tools
subject: How do I get a current date and time in a JLabel?
Similar Threads
Layout problems!!
How to get these two classes to interact?
appletviewer
Help with screen output in applet
GridLayout troubles
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter