我构造了3个窗口,主窗口,副窗口还有第三个窗口,我的第三个窗口的构造是写在主窗口里面的,但是我现在想副窗口也能共享第三个窗口的信息,我应该怎么做?? 就是怎么实现三个类之间的信息共享?? 急~~ 谢谢答复

解决方案 »

  1.   

    你说的是html
    还是swing awt
      

  2.   

    你说的是html
    还是swing awt
      

  3.   

    既然有构造,应该是swing awt之类的吧import java.awt.event.*;
    import javax.swing.*;
    public class CSDN extends JFrame {

    Child1 child1 = null;
    Child2 child2 = null;
    public CSDN(){
    super("test");
    this.setFocusable(true);
    init();
    setLocation(200, 100);
    pack();
    setVisible(true);
    this.addWindowListener(new WindowListener());
    }

    void init(){
    child1 = new Child1(this);
    child2 = new Child2(this);
    }

    class Child1 extends JFrame {
    CSDN father;
    JTextArea jt = new JTextArea(); 
    Child1(CSDN father){
    super("child1");
    this.father = father;
    this.setFocusable(true);
    setLocation(200, 200);
    jt.setText("input something");
    this.getContentPane().add(jt);
    pack();
    setVisible(true);
    this.addWindowListener(new WindowListener());
    }
    }

    class Child2 extends JFrame implements MouseListener{
    CSDN father;
    JButton button = new JButton("");
    Child2(CSDN father){
    super("child2");
    this.father = father;
    this.setFocusable(true);
    setLocation(200, 300);
    button.setText("click me");
    button.addMouseListener(this);
    this.getContentPane().add(button);
    pack();
    setVisible(true);
    this.addWindowListener(new WindowListener());
    }
    public void mouseClicked(MouseEvent e) {
    JOptionPane.showMessageDialog(this,father.child1.jt.getText());
    }
    public void mouseEntered(MouseEvent e) {
    }
    public void mouseExited(MouseEvent e) {
    }
    public void mousePressed(MouseEvent e) {
    }
    public void mouseReleased(MouseEvent e) {
    }
    }

    class WindowListener extends WindowAdapter{
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    }

    public static void main(String[] args){
    CSDN csdn = new CSDN();
    }
    }
      

  4.   

    2楼麻烦说清楚一点,谢谢~~3楼我用的是swing
      

  5.   

    father.child1.jt.getText()
    这行看见了没?
    去找老爹的另一个儿子的某属性,不是很清楚吗