Hi. I had employ name Text Field in 1st panel in D module. when i click generate button the employ name automatically update in display panel Employe Name Textfield in E module. so in both the panels the value must be same. how can i get the value from D module and update in E module by using Java Swing.
+1
A:
Swing relies heavily on the Obeserver pattern. You can use this pattern to help your E module know when the generate button is clicked.
If your E module has a reference to your D module, you can add E as an ActionListener
to the generate button. You can then pull the text from the D module when the action is fired. A brute-force approach is mapped out below:
public class DModule {
private JButton genButton = new JButton("generate");
private JTextField empNameTF = new JTextField();
// ---more code ---
public void addGenButtonListener (ActionListener l) {
genButton.addActionListener(l);
}
public String getEmpName() {
return empNameTF.getText();
}
}
public class EModule implements ActionListener {
DModule d = null;
JTextField myEmpNameTF = new JTextField();
public EModule (DModule d) {
this.d = d;
d.addGenButtonListener(this);
}
// --- more code ---
public void actionPerformed(ActionEvent event) {
myEmpNameTF.setText(d.getEmpName());
}
}
akf
2010-05-31 03:16:56
thanks a lot buddy
charan
2010-05-31 03:25:27
@charan - if this solved your problem, consider marking this answer as accepted
Gnoupi
2010-05-31 07:51:37