Monday, November 12, 2012

Time Functions in Java!


     This program shows real time update every second. It uses basic time functions and classes in java.
//code:
import javax.swing.Timer;
import java.awt.event.*;
import java.util.*;

public class Update implements ActionListener {
Timer t = new Timer(1000,this);
// every second

Update() {
t.start();
}

public static void main(String args[]) {
Update td = new Update();
// to keep the JVM running, a frame is needed
java.awt.Frame dummy = new java.awt.Frame();
dummy.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == t) {
System.out.println ("\007Tik Tak " + Calendar.getInstance().getTime());
}
}
}

No comments:

Post a Comment