passing struct back to parent class after "ok" click

I'm writing a class that extends JFrame, it will accept a list of names as an array and then create corresponding check boxes and labels on the frame.  I don't have a problem getting the JFrame (optionPanel) to appear, but the question I have is how do I pass the subsequent array of Booleans (checked or not) back to the calling class after the "ok" button is clicked.  If I knew what class was going to call the optionPanel I could just set a variable in the parent class, but since optionPanel can be called from as many as 20 different classes I'm looking for a more generic way to do it.

 public class optionPanel extends JFrame{
    public optionPanel(array names){
       createCheckBoxes();
       
       public void cmdOK_Click(){
          buildBooleanArray();
          cmdClose_Click();
       }
    }
 }
I'm assuming the code I'm looking for would go into cmdClose_Click();
zephar410Asked:
Who is Participating?
 
JakobAConnect With a Mentor Commented:
Your constructor function cannot pass bac anything but the reference to your new object.

But is not that enough?  you kan place the desired dat in the class as public variables:

 public class optionPanel extends JFrame{
   public array myNames;
   public optionPanel(array names){
      myNames = names;
      createCheckBoxes();
     
      public void cmdOK_Click(){
         buildBooleanArray();
         cmdClose_Click();
      }
   }
 } // end of class optionPanel

 public someOtherClass {
   optionPanel myObject;
   public sometype methodName( ) {
     myObject = new optionPanel( parameeters );
     return myObject.myNames;
   }
 } // end og class someOtherClass

best JakobA
0
 
zephar410Author Commented:
Ahh yes... a week of vacation will make one ask questions with such obvious answers :]

Thanks,
Derek
0
All Courses

From novice to tech pro — start learning today.