JBuilder9,有两个窗体通信 JBuilder9,有两个窗体:Form1,Form2;Form1为主窗体,Form2为Form1调用的条件查询窗体,怎样在Form2关闭时返回SLQ语句给Form1且Form1自动执行该SQL操作?望指教啊,最好附代码啊!!越详细越好 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的愚蠢做法是返回Form1时,利用Form2传递过来的查询条件再作一次查询,呵呵功能倒是实现了,是不是很蠢啊希望看到更好的方法! 在Form2的closing事件里调用Form1的一个查询数据库方法,以form2获得的sql语句做参数. 监听componentRemoved事件,在其中调用父container的读取子container的text内容 void this_componentRemoved(ContainerEvent e) { ((ParentDialog1)this.getParent()).setText(this.textField.getText()); }ParentDialog1.setText(String) 是把输入的参数记录到它的类的类变量。这样就实现了子窗口与父窗口通信 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); }} 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); }} J2SE + SQL Server 开发的桌面程序能打包成安装程序 java 文件拷贝 java测试执行效率 java 界面布局问题 关于函数参数的引用和复制 菜鸟问题 愚蠢可笑 帮我看看这部分代码吧,再弄不出来我快要疯了,天啊,明天大街上难道会多一个疯婆子? 怎么控制button,panel,frame之类的大小呀? 请教哪里有jrun下载? 请问如何实现java开发的GUI应用程序转化成exe运行?? 请问这段java代码为什么没有结果输出呀? Java做ERP合适吗?Java主要用在什么方面?
监听componentRemoved事件,在其中调用父container的读取子container的text内容 void this_componentRemoved(ContainerEvent e) {
((ParentDialog1)this.getParent()).setText(this.textField.getText()); }ParentDialog1.setText(String) 是把输入的参数记录到它的类的类变量。这样就实现了子窗口与父窗口通信
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);
}
}
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);
}
}