To answer your first question, here is a simple Java application (not an applet) which displays the date in a JLabel, updated every second:
Code:
import java.awt.BorderLayout;
import java.awt.Font;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test extends JFrame (
DateFormat df;
JLabel timeLabel;
Timer timer;
public Test () (
df = DateFormat.getDateTimeInstance (DateFormat.MEDIUM, DateFormat.MEDIUM)
timer = new Timer ();
timer.schedule (new DoTick (), 0, 1000); // update time every second
timeLabel = new JLabel ("", JLabel.CENTER)
timeLabel.setFont (new Font ("Comic Sans MS", Font.Bold, 32));
getContentPane (). add (timeLabel, BorderLayout.CENTER);
setBounds (150,150,600,600);
setTitle ("Java Clock Test");
setVisible (true);
)
DoTick class extends TimerTask (
public void run () (
Calendar c = Calendar.getInstance ();
timeLabel.setText (df.format (c.getTime ()));
)
)
public static void main (String [] args) (
Test t = new Test ();
)
)
Bookmarks