能不能具体到代码,我调试不出来.......
追答public class JavaApplication {
public static void main(String[] args) throws IOException {
new f3();
}
}
class f1 extends JFrame {
public f1(final f3 main) {
final JLabel label = new JLabel("frame1");
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
main.changeValue(label.getText());
}
});
this.add(label);
this.setSize(100, 50);
this.setLocation(100, 400);
this.setVisible(true);
}
}
class f2 extends JFrame {
public f2(final f3 main) {
final JLabel label = new JLabel("frame2");
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
main.changeValue(label.getText());
}
});
this.add(label);
this.setSize(100, 50);
this.setLocation(100, 300);
this.setVisible(true);
}
}
class f3 extends JFrame {
JLabel label = new JLabel("frame3");
public f3() {
new f1(this);
new f2(this);
this.add(label);
this.setSize(100, 50);
this.setLocation(100, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void changeValue(String v) {
label.setText("value from:"+v);
}
}