JFrame1{
new JFrame2();
……
String change;
}JFrame2{
JButton jb = new JButton();
……
public void actionPerformed(ActionEvent e) {
……
}
}
如上面的两个JFrame类,JFrame1里面new了个JFrame2,我现在想在JFrame2的一个JButton被点击的时候JFrame1的change变量改变,该怎么做啊?谢谢!!
new JFrame2();
……
String change;
}JFrame2{
JButton jb = new JButton();
……
public void actionPerformed(ActionEvent e) {
……
}
}
如上面的两个JFrame类,JFrame1里面new了个JFrame2,我现在想在JFrame2的一个JButton被点击的时候JFrame1的change变量改变,该怎么做啊?谢谢!!
private JFrame1 jframe1 = new JFrame1();
new JFrame2(jframe1);
……
String change;
}
JFrame2{
private JFrame1 jframe1 = null;
public JFrame2(JFrame1 jframe1){
this.jframe1 = jframe1;
}
JButton jb = new JButton();
……
public void actionPerformed(ActionEvent e) {
……
}
} 实现方式有很多种的。这只不过是比较容易理解的一种而已。习惯性的,我不会使用这种
new JFrame2();
……
String change;
} JFrame2{
JButton jb = new JButton();
JFrame1 frame1;
……
public void actionPerformed(ActionEvent e) {
frame1.setTitle(change);
……
}
}