Problem with event on custom JPanels

Greetings!

I need to create a GUI that offers a view of an entire month's days, allows a certain selection for each day using JRadioButtons and displays the user's input for each week.

So far i've created:

- a "DayPanel" class that contains the radio buttons and variables for storing input

- a "WeekPanel" class with a variable - length array of "DayPanels" (depending on the week's number of days) and a "countPanel" that displays user input for that week.

This "countPanel" is updated by a call to a method in the parent "WeekPanel" from a "DayPanel's" ActionListener passing the "DayPanel's" selection value.

- a MonthPanel" class to display an entire month which contains an array of weekPanels.

All classes extend JPanel.

If i use a single "WeekPanel" everything works fine. However,as soon as more than one is in use only the "countPanel" of the "WeekPanel" that was last added to the "MonthPanel" is updated, regardless on which "WeekPanel" the selection change occured.

What's even stranger is that ActionEvent.getSource().getParent() returns the name of the correct "WeekPanel" but, as mentioned, only the last "WeekPanel's" "countPanel" is affected.

Anybody have an idea ?

THX,

c2

[1282 byte] By [confused2a] at [2007-10-3 8:35:47]
# 1
Maybe you are using some sort of static field where you don't need it? Or somehow you have a reference to the last created week? I am just guessing without seeing any code.
zadoka at 2007-7-15 3:43:23 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks for the quick reply!

Concerning static fields:

When a selection change occurs i create a reference to the originating container (WeekPanel) by doing the following in actionPerformed():

JRadioButton rb = (JRadioButton)e.getSource();

DayPanel dp = (DayPanel)rb.getParent();

WeekPanel wp = (WeekPanel)dp.getParent();

(shouldn't that ensure the right WeekPanel is affected ?)

Then i call the update method on wp which is declared

public static void updateLabels(float , float , float , float)

(this doesn't do anything fancy, it just increments or decrements four variables of the WeekPanel)

If the method's not declared static i get an IncompatibleClassChangeError when calling WeekPanel.updateLabels().

As for references:

The WeekPanels in a MonthPanel (and the DayPanels in a weekPanel) are created in the following manner:

weekPanels = new WeekPanel[weekNumbers.length];

for(int i=0; i<weekNumbers.length; i++)

weekPanels = new WeekPanel();

(IMHO that shouldn't leave any "loose" references ?)

c2.>

confused2a at 2007-7-15 3:43:23 > top of Java-index,Desktop,Core GUI APIs...
# 3
Problem solved!!! The culprit was actually a static variable in class WeekPanel.Thanks for the pointers!c2.
confused2a at 2007-7-15 3:43:23 > top of Java-index,Desktop,Core GUI APIs...