Here is a piece of code to build a Java clock, using swing,
Timer t = new Timer(1000, updateClockAction);
t.start();
ActionListener updateClockAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Assumes clock is a custom component
lblTime.setText(System.currentTimeMillis()+"");
// OR
// Assumes clock is a JLabel
lblTime.setText(new Date().toString());
}
};
Timer t = new Timer(1000, updateClockAction);
t.start();
ActionListener updateClockAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Assumes clock is a custom component
lblTime.setText(System.currentTimeMillis()+"");
// OR
// Assumes clock is a JLabel
lblTime.setText(new Date().toString());
}
};
1 comments:
Thank you so much for the information the updates are going to be very helpful for me in the near future. I always keep searching for more such updates this helps me in increasing my knowledge. For support regarding Norton Antivirus Support
Post a Comment