Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

panel communication

  Asked By: Emily    Date: Jun 25    Category: Java    Views: 1353
  

What is the best way to communicate between two panel?

I have a panel1 panel with a txt1 TextField
and
I have a panel2 panel with a btn Button.

In the main sub i make a add(panel1), add(Panel2).

When i click btn(in the panel2) i would like to change the txt content(in the
panel1).

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Joseph Evans     Answered On: Jun 25

Panel 2 needs a reference to panel  1. Thus, you could pass panel1 as an
argument to the contructor of panel2:

public class Panel2 extends Panel{

private Panel panel1;

public Panel2(Panel panel1){
this.panel1 = panel1;
}

}


And then panel1 should include some method for setting the value of the
text field, so that panel2 can do:

button = new Button();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
panel1.setText1("New text");
}
});

 
Didn't find what you were looking for? Find more on panel communication Or get search suggestion and latest updates.




Tagged: