Simple Java Digital Clock

Here is a simple #java digital clock idea that can be used as the bases for something allot nicer or even eventually a eye candy widge/icon/desklet is you are artistically inclined.

This is the simple outcome and as you can see very simple but a nice starting point.

SimpleJavaClock

Here you have a code snip of the ClockLabel


ClockLabel clock = new ClockLabel();
clock.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
clock.setForeground(Color.blue);
clock.setHorizontalAlignment(SwingConstants.CENTER);

The full code is here SimpleJavaClock you can simply copy and paste and compile and run.

This is how you compile via command line:

$ javac SimpleJavaClock.java
$ java -cp . SimpleJavaClock

If you are going to compile and run via command line the easiest thing to do is remove the first line of the code (package name)

Leave a Reply