monthCombo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
dayCombo.removeAllItems();
GregorianCalendar c = new GregorianCalendar();
// set month to the month the user selected
// 0 = Jan, 1 = Feb, etc..
c.set(Calendar.MONTH, monthCombo.getSelectedIndex());
// this line gets the last day of the month
int lastDay = c.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
// just testing the output
JOptionPane.showMessageDialog(null, c.getActualMaximum(GregorianCalendar.DAY_OF_MONTH));
// populate the dayCombo box with each day in the month
for (int i = 1; i <= lastDay; i++)
dayCombo.addItem(new Integer(i));
}
});
So there are two combo boxes in my program. One for the month and one for the day. I have it so when the user selects the month the next combo box is populated with the days in that month. Above is the actionlistener for the month combo box that populates the dayCombo box.
Here is the weird thing. It gives me the the correct last day for every month.. except it gives me 31 days for February.

New Topic/Question
Reply



MultiQuote




|