Java Reference
In-Depth Information
46 /** Set a new minute */
47 public void setMinute( int minute) {
48 this .minute = minute;
49 paintClock();
50 }
51
52
set a new minute
paint clock
/** Return second */
53
public int getSecond() {
54
return second;
55 }
56
57 /** Set a new second */
58 public void setSecond( int second) {
59 this .second = second;
60 paintClock();
61 }
62
63
set a new second
paint clock
/** Return clock pane's width */
64
public double getW() {
65
return w;
66 }
67
68 /** Set clock pane's width */
69 public void setW( double w) {
70 this .w = w;
71 paintClock();
72 }
73
74
set a new width
paint clock
/** Return clock pane's height */
75
public double getH() {
76
return h;
77 }
78
79 /** Set clock pane's height */
80 public void setH( double h) {
81 this .h = h;
82 paintClock();
83 }
84
85 /* Set the current time for the clock */
86 public void setCurrentTime() {
87 // Construct a calendar for the current date and time
88 Calendar calendar = new GregorianCalendar();
89
90
set a new height
paint clock
set current time
// Set current hour, minute and second
91
this .hour = calendar.get(Calendar.HOUR_OF_DAY);
92
this .minute = calendar.get(Calendar.MINUTE);
93
this .second = calendar.get(Calendar.SECOND);
94
95 paintClock(); // Repaint the clock
96 }
97
98
paint clock
/** Paint the clock */
99
protected void paintClock() {
paint clock
100
// Initialize clock parameters
101
double clockRadius = Math.min(w, h) * 0.8 * 0.5 ;
get radius
set center
102
double centerX = w / 2 ;
103
double centerY = h / 2 ;
104
105
// Draw circle
 
 
Search WWH ::




Custom Search