PDA

View Full Version : Calling method from another class



neo_philiac
05-04-2010, 02:49 PM
I have a quick question:

I have two classes. MainPanel and SubPanel

I am putting SubPanel inside the MainPanel dynamically. So I have a method inside SubPanel called (toggleSection). All I am trying to do is that, in the MainPanel I am rearranging the components (all JPanels - instance of SubPanel). So when I get the name of the component, I get all the components in my contentPane and call the method toggleSection for that component. Apparently I can get name & location for the component but not the method. Any solution?


public static void moveToTop(String name) {

int i;
Component ar[] = contentPane.getComponents();
// This pass to get the requested component and move it to top.
// this pass to move all the other

for (i = 0; i < ar.length; i++) {
if (ar[i].getName() != name) {
ar[i].??????? // Cant get the method here.
contentPane.add(ar[i]);
contentPane.repaint();
contentPane.validate();
Debugger.debug(1, "Component Location :" + ar[i].getLocation() + " Name: " + ar[i].getName());
}
}


}


Thanks