Java: Example - Extend Text Clock
Here are several possible extensions to Example - Text Clock 2.- Minor changes. The time should be centered in the field.
This can be done by calling the
setHorizontalAlignment(JTextField.CENTER)
. Another similar change would be to make the text field uneditable by the user. A call tosetEditable(false)
would accomplish this. Where should these calls go? - Leading zeros. The convention for showing digital time is to use two digits with leading zeros. For example, 5 minutes and 3 seconds after 8 is usually shown as "08:05:03", not "8:5:3". This requires the addition of some tests to add an extra "0" character when numbers are less than 10.
- AM/PM. The clock could be changed to use the 12-hour system, and show an additional "AM" or "PM". This option could be built-in, or it could be settable.
- Alarm or Timer. A more ambitious project is to make
an alarm clock or countdown timer. This requires the addition of
controls to turn this feature on and off.
Do you want a Snooze button?
Design the user interface first. It would be easiest to always show the alarm time as a smaller display, with a check box or toggle button to turn it on and off.