I am creating a calendar program we need to do scheduling. I am using BorderLayout, the northern panel contains drop-down selections for month and year, the center panel contains the calendar itself. Upon initial entry the calendar for the current month is presented, with today's date highlighted. All works fine.
When a month or year is selected from the drop-down I want to recreate the center panel. On the Mac where I have been developing it things work fine. Porting it to Windows finds that the center panel always shows the current month. Not having to recreate a panel before I am at a loss as to why it is not working on the Windows platform (XP).
The code that calls the code to create the month panel is:
Code:monthCombo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
d.set(Calendar.MONTH, monthCombo.getSelectedIndex());
CreateMonth (d, false);
repaint();
}
});
The CreateMonth code is:
Code:private void CreateMonth (GregorianCalendar date, boolean redraw)
{
int curDate = date.get(Calendar.DAY_OF_MONTH);
int curMonth = date.get(Calendar.MONTH);
int curYear = date.get(Calendar.YEAR);
// Month and Year fields
for ( String month : months )
monthCombo.addItem(month);
monthCombo.setSelectedIndex(curMonth);
for ( int i = 1900; i < 2101; i++ )
yearCombo.addItem(i);
yearCombo.setSelectedIndex(curYear - 1900);
// add the Month and Years
if (redraw)
{
JPanel selectPanel = new JPanel();
selectPanel.setOpaque(true);
selectPanel.setBackground(new Color(153,255,153));
selectPanel.setLayout(new GridLayout(1,4));
selectPanel.add(todayButton);
selectPanel.add(monthCombo);
selectPanel.add(yearCombo);
selectPanel.add(mathButton);
add(selectPanel, BorderLayout.NORTH);
}
// add the days
JPanel monthPanel = new JPanel();
monthPanel.setOpaque(true);
monthPanel.setBackground(new Color(153,255,153));
monthPanel.setLayout(new GridLayout(7,7));
BevelBorder bevel = new BevelBorder(BevelBorder.LOWERED);
for (String day : days)
{
JLabel temp = new JLabel(day, JLabel.CENTER);
temp.setBorder(bevel);
temp.setOpaque(true);
temp.setBackground(Color.YELLOW);
monthPanel.add(temp);
}
// Move days
GregorianCalendar gDate = new GregorianCalendar();
int curJulDay = 0;
if (gDate.isLeapYear(curYear)) curJulDay = leapJulDay[curMonth];
else curJulDay = julianDay[curMonth];
int day = 1;
date.set(Calendar.DAY_OF_MONTH, 1);
for (int r = 0; r < 6; r++)
{
for (int c = 0; c < 7; c++)
{
JLabel temp = new JLabel("");
if (r == 0 && c < (date.get(Calendar.DAY_OF_WEEK) - 1))
{
monthPanel.add(temp);
}
else
{
if (day <= daysInMonth[curMonth])
{
temp = new JLabel("" + day + " / " + curJulDay++, JLabel.CENTER);
temp.setBorder(bevel);
temp.setOpaque(true);
if (day == curDate) temp.setBackground(new Color(000,255,255));
else temp.setBackground(new Color(153,153,255));
day++;
}
}
monthPanel.add(temp);
}
}
add(monthPanel, BorderLayout.CENTER);
date.set(Calendar.DAY_OF_MONTH, curDate);
}

