ptg7068951
182 HOUR 13:Building a Simple User Interface
43: monthName = “June”;
44: break;
45: case (7):
46: monthName = “July”;
47: break;
48: case(8):
49: monthName = “August”;
50: break;
51: case(9):
52: monthName = “September”;
53: break;
54: case(10):
55: monthName = “October”;
56: break;
57: case(11):
58: monthName = “November”;
59: break;
60: case(12):
61: monthName = “December”;
62: }
63: time = monthName + “ “ + day + “, “ + year + “ “
64: + hour + “:” + minute;
65: returntime;
66: }
67: }
The getTime()method in ClockPanelcontains the same technique for
retrieving the current date and time as the ClockTalkapplication from
Hour 7. This method has the keyword finalwhen it is declared in line 15:
final String getTime() {
// ...
}
Using finalprevents themethod from being overridden in a subclass.
This is required for ClockPanelto be a GUI component.
The panel is created in the constructor in Lines 6–13. The following things
are taking place:
. Line 8—The date and time are retrieved by calling getTime()and
storing the string it returns in the currentTimevariable.
. Line 9—Anew label named timeis created with the text “Time: “.
. Line 10—currentTimeis used as the text of new label component
called current.
LISTING 13.3 Continued