A clock with no hands and no numbers is just a circle.
Since arcs are drawn anticlockwise from 0 (on the right, or 3 p.m.) through 90 (12 p.m.), then 180 (9 p.m.), then 270 (6 p.m.), and finally back to 360 (3 p.m.), it is possible to calculate the arc's position for the second hand by using (15-s)*6%360
.
Go to the
paintControl()
method of thePaintListener
insideClockView
.Add a variable
seconds
that is initialized tonew Date().getSeconds()
.Get
SWT.COLOR_BLUE
via the display and store it in a local variableblue
.Set the background color of the graphics context to
blue
.Draw an arc using the previous formula to draw the second hand.
The code should look like the following:
public void paintControl(PaintEvent e) { int seconds = new Date().getSeconds(); int arc = (15-seconds) * 6 % 360; Color blue = e.display.getSystemColor(SWT.COLOR_BLUE); e.gc.setBackground(blue); e.gc.fillArc(e.x,e.y,e.width-1,e.height-1,arc-1,2); }
Start Eclipse and show the...