Hope you guys enjoy !
import java.awt.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
import java.util.*;
import java.text.*;
class DigiClock extends JLabel implements ActionListener {
private DateFormat df = DateFormat.getTimeInstance();
public DigiClock() {
setHorizontalAlignment(JLabel.CENTER);
setOpaque(true);
setBackground(Color.white);
setFont(new Font("Verdana", Font.BOLD,26));
Timer tim = new Timer(1000,this);
tim.start();
}
public DigiClock(String zone) {
this();
df.setTimeZone(TimeZone.getTimeZone(zone));
}
public void actionPerformed(ActionEvent e) {
setText(df.format(new Date()));
}
}
public class DemoDigiClock extends JFrame {
private DigiClock DC = new DigiClock();
public DemoDigiClock() {
JLabel l1 = new JLabel("Local time",JLabel.CENTER);
l1.setFont(new Font("Serif",Font.PLAIN,18));
setLayout(new GridLayout(2,2,5,5));
add(DC); add(l1);
setSize(250,125);
setVisible(true);
}
public static void main(String[] arg) {
new DemoDigiClock();
}
}
For those who doesn't understand this, I recommend you read more about java...


Sign In
Create Account



Back to top









