Java Digital Clock Program

Here's the rest of the code that makes up the digital clock. The program is made up of three classes:

  • TheTimestamp class that can give you the current hours, minutes, and seconds.

  • A class called “ClockView”. This holds everything related to the visual appearance of the clock on screen.

  • A class called “clock” that has overall control, and is where execution starts.

For a small example like this, we could merge everything into one class, and make it a dozen lines shorter. By keeping the design elements in separate classes, you can form a better idea of how classes should be used in bigger programs and systems.

The main() routine where execution starts

We'll start with the class that has overall control, ...

Get Just Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.