Time for action – drawing a seconds hand
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 ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition 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.