A clock with no hands and no numbers is just a circle. To change this, a second hand will be drawn using a filled arc.
Since arcs are drawn anticlockwise from 0 (on the right, or 3 o'clock) through 90 degrees (12 o'clock), then 180 degrees (9 o'clock), then 270 degrees (6 o'clock), and finally back to 360 degrees (3 o'clock), it is possible to calculate the arc's position for the second hand using the expression (15 – seconds) * 6 % 360.
Go to the
drawClock
method of theClockView
class.Add a variable called
seconds
that is initialized toLocalTime.now().getSecond()
.Get the
SWT.COLOR_BLUE
via the display, and store it in a local variable,blue
.Set the background color of the graphics context to
blue
.Draw an arc using the formula mentioned earlier to draw the second hand.
The code should look like this:
public void paintControl(PaintEvent e) { e.gc.drawArc(e.x, e.y, e.width-1, e.height-1, 0, 360); int seconds = LocalTime.now().getSecond(); int arc...