Java Reference
In-Depth Information
52.
{
53.
dayBox.addItem(Integer.toString(d));
54.
}//
for
55.
monthBox.setMaximumRowCount(12);
56.
dayBox.setMaximumRowCount(10);
57.
yearBox.setMaximumRowCount(4);
58.
}
59.
60.
private void
setDayListTo(
int
desiredLength){
61.
int
currentLength = dayBox.getItemCount();
62.
if
(currentLength < desiredLength){
63.
for
(
int
i=currentLength+1; i <= desiredLength; i++) {
64.
dayBox.addItem(Integer.toString(i));
65.
}//
for i
66.
}
67.
else if
(currentLength > desiredLength)
68.
{
69.
for
(
int
i=currentLength-1; i >= desiredLength; i--) {
70.
dayBox.removeItemAt(i);
71.
}//
for i
72.
}
73.
}
74.
75.
public
String getDate(){
76.
return
((String)dayBox.getSelectedItem()+"."+
77.
(String)monthBox.getSelectedItem()+" "+
78.
(String)yearBox.getSelectedItem());
79.
}
80.
81.
class
CalenderListener
implements
ActionListener
82.
{
83.
public void
actionPerformed(ActionEvent evt){
84.
String actionCommand = evt.getActionCommand();
85.
int
year = Integer.parseInt(((String)yearBox.getSelectedItem()).trim());
86.
int
month = monthBox.getSelectedIndex();
87.
if
((year > 2099) || (year < 1901)){
88.
year = 2000;
89.
yearBox.setSelectedItem("2000");
90.
}
91.
if
(actionCommand.equals("YearChanged"))
92.
{
93.
if
((year%4==0)&&(month == 1)){
94.
setDayListTo(29);
95.
}
96.
}
97.
else if
(actionCommand.equals("MonthChanged"))
Search WWH ::
Custom Search