Java Reference
In-Depth Information
7.
Set the values to 1 through 12 using a loop.
8.
In MonthCh, add the following statements to get a Calendar object, retrieve the current
month, and set the selected value to the current month.
Calendar c = Calendar.getInstance();
select(String.valueOf(c.get(Calendar.MONTH)+1));
Because Java always assigns a value of zero to the first item in a group (i.e., the first character in a string is at
location zero, not location one), you must add 1 to the returned value to obtain the correct value for the current
month. In other words, the value of MONTH during January is zero. (Ouch!) So, the “trick” to get the commonly
accepted month number is to add 1 to the returned value. We placed the get inside of the select statement so that the
correct value will be selected when the choice is first displayed.
9.
In DayCh:
Set the size to 44, 21
Set the values to 1 through 31 using a loop
Calendar object)
Retrieve the current day (the DAY_OF_MONTH field in a
Make the current day the selected value
10.
In YearCh:
Set the size to 51, 21
Calendar object's YEAR field)
Retrieve the current year (a
Set the values to the previous year, the current year, and the next year using a loop
Make the current year the selected value
Create 3 new visual Java classes that are extensions of the Choice class called HourCh,
MinCh, and AMPMCh and set all their sizes to 44, 21.
11.
12.
In HourCh:
Set the values to 0 through 12 using a loop.
Retrieve the current hours (the HOUR_OF_DAY field).
The HOUR_OF_DAY field contains a value between 0 and 23, so you will need to change any value greater than
12 to the correct value before selecting it in the choice. The logic for doing this is as follows:
if the current hours is less than or equal to 12 select the value in the choice values
else subtract 12 from the value and select the result in the choice values
13.
In MinCh:
Set the values to 0 through 59 using a loop.
Retrieve the current minutes (the MINUTE field).
Make the current minutes the selected value.
Search WWH ::




Custom Search