programming-examples/java/Servlets_Session_Swing_Util/Display time in Applet.java

28 lines
797 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
Display time in Applet
class AppletTimer
{
javax.swing.Timer timer;
String s;
SimpleDateFormat timef = new SimpleDateFormat("HH:mm");
//private Launch ll = new Launch();
//public AppletTimer(final Applet ap)
public AppletTimer(final JTextField tf)
{
timer = new javax.swing.Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
s = timef.format(new Date(System.currentTimeMillis()));
//ap.showStatus(s);
tf.setText(s);
}
});
timer.start();
}
}
And in ur applet create a JTextField and use like this
in the init() method
JTextField jtf = new JTextField();
new AppletTimer(jtf);