JBuilder9,有两个窗体:Form1,Form2;Form1为主窗体,Form2为Form1调用的条件查询窗体,怎样在Form2关闭时返回SLQ语句给Form1且Form1自动执行该SQL操作?望指教啊,最好附代码啊!!越详细越好

解决方案 »

  1.   

    我的愚蠢做法是返回Form1时,利用Form2传递过来的查询条件再作一次查询,呵呵功能倒是实现了,是不是很蠢啊希望看到更好的方法!
      

  2.   

    在Form2的closing事件里调用Form1的一个查询数据库方法,以form2获得的sql语句做参数.
      

  3.   


    监听componentRemoved事件,在其中调用父container的读取子container的text内容  void this_componentRemoved(ContainerEvent e) {
          ((ParentDialog1)this.getParent()).setText(this.textField.getText());  }ParentDialog1.setText(String) 是把输入的参数记录到它的类的类变量。这样就实现了子窗口与父窗口通信
      

  4.   

    package Comm;import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Frame1 extends JFrame {
      JTextArea jTextArea1 = new JTextArea();
      JButton jButton1 = new JButton();
      JLabel jLabel1 = new JLabel();
      JButton jButton2 = new JButton();
      Frame2 child;  public Frame1() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public static void main(String[] args) {
        Frame1 frame1 = new Frame1();
        frame1.setVisible(true);
        frame1.show();
      }
      private void jbInit() throws Exception {
        jTextArea1.setText("jTextArea1");
        jButton1.setText("Make Frame 2");
        jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
        jLabel1.setText("Frame 1");
        jButton2.setText("jButton2");
        jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
        this.getContentPane().add(jTextArea1, BorderLayout.CENTER);
        this.getContentPane().add(jButton1, BorderLayout.WEST);
        this.getContentPane().add(jLabel1, BorderLayout.NORTH);
        this.getContentPane().add(jButton2, BorderLayout.SOUTH);
      }  void jButton1_actionPerformed(ActionEvent e) {
        child=new Frame2(this);
        child.setVisible(true);
        child.show();
      }  void jButton2_actionPerformed(ActionEvent e) {
        this.jTextArea1.setText(child.jTextField1.getText());
      }
    }class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
      Frame1 adaptee;  Frame1_jButton1_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
      }
    }class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
      Frame1 adaptee;  Frame1_jButton2_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
      }
    }
      

  5.   

    package Comm;import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Frame2 extends JFrame {
      JLabel jLabel1 = new JLabel();
      JTextField jTextField1 = new JTextField();
      JButton jButton1 = new JButton();
      Frame1 parent;
      public Frame2(Frame1 Parent) {
        parent =Parent;
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }  private void jbInit() throws Exception {
        jLabel1.setText("Frame 2");
        jTextField1.setText("jTextField1");
        jButton1.setText("Get Frame1 Text");
        jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
        this.getContentPane().add(jLabel1, BorderLayout.NORTH);
        this.getContentPane().add(jTextField1, BorderLayout.CENTER);
        this.getContentPane().add(jButton1, BorderLayout.SOUTH);
      }  void jButton1_actionPerformed(ActionEvent e) {
        this.jTextField1.setText(parent.jTextArea1.getText() );
      }
    }class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener {
      Frame2 adaptee;  Frame2_jButton1_actionAdapter(Frame2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
      }
    }