Java Reference
In-Depth Information
14.34
Write code fragments to display the lower half of a circle with radius 50 filled with
the red color.
14.35
Write code fragments to display a polygon connecting the following points: ( 20 , 40 ),
( 30 , 50 ), ( 40 , 90 ), ( 90 , 10 ), ( 10 , 30 ), and fill the polygon with green color.
14.36
Write code fragments to display a polyline connecting the following points: ( 20 , 40 ),
( 30 , 50 ), ( 40 , 90 ), ( 90 , 10 ), ( 10 , 30 ).
14.12 Case Study: The ClockPane Class
This case study develops a class that displays a clock on a pane.
Key
Point
The contract of the ClockPane class is shown in FigureĀ 14.41.
javafx.scene.layout.Pane
The getter and setter methods for
these data fields are provided in the class,
but omitted in the UML diagram for brevity.
ClockPane
-hour: int
-minute: int
-second: int
-w: double
-h: double
The hour in the clock.
The minute in the clock.
The second in the clock.
The width of the pane that contains the clock.
The height of the pane that contains the clock.
+ClockPane()
+ClockPane(hour: int, minute:
int, second: int)
+setCurrentTime(): void
Constructs a default clock for the current time.
Constructs a clock with the specified time.
Sets hour, minute, and second to current time.
F IGURE 14.41
ClockPane displays an analog clock.
Assume ClockPane is available; we write a test program in Listing 14.20 to display
an analog clock and use a label to display the hour, minute, and second, as shown in
FigureĀ 14.42.
(0, 0)
(xEnd, yEnd)
12
handLength
9
3
(centerX, centerY)
6
(a)
(b)
F IGURE 14.42
(a) The DisplayClock program displays a clock that shows the current
time. (b) The endpoint of a clock hand can be determined, given the spanning angle, the
hand length, and the center point.
 
 
 
Search WWH ::




Custom Search