To show the effect of changing the TimeZone
, it is necessary to add an hour hand to the clock. When the TimeZone
is changed in the drop-down, the hour hand will be updated.
Add a
zone
field to theClockWidget
along with a setter:private ZoneId zone = ZoneId.systemDefault(); public void setZone(ZoneId zone) { this.zone = zone; }
Getters and setters can be generated automatically. Once the field is added, navigate to Source | Generate Getters and Setters. It can be used to generate all missing getters and/or setters; in addition, a single getter/setter can be generated by typing
set
in the class body, followed by Ctrl + Space (Cmd + Space on macOS).Add an hour hand in the
drawClock
method using the following:e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK)); ZonedDateTime now = ZonedDateTime.now(zone); int hours = now.getHour(); arc = (3 - hours) * 30 % 360; e.gc.fillArc(e.x, e.y, e.width-1, e.height-1, arc - 5, 10);
To update the clock when...