在java中,一个窗口控制另一个窗口
解决方案 »
- 关于JAVA异常处理的问题
- 文件目录显示问题
- java String 与 .net string 的区别?深入点讲.
- sun公司为协议处理框架提供了基于HTTP协议的实现,不过,这些实现类都没有在JDK类库中公开,它们都位于sun.net.www包或者其子包中,请问sun.net.www包去哪找,我找不到啊!
- 关于右键菜单
- Java中类型的转换(虽然没有分,但是还是希望各位大侠,能帮我下下,先谢谢了)
- poi读写excel文件
- 将字符串参数传递给方法,空格怎么不见了
- 谁能在linux下,帮俺部署一下,俺做的文件,高分!!!
- 请大家帮忙,谢谢!
- 书上的例子,通不过编译,请大家帮忙找错误,我是新手。
- 不是构造器,为什么这里会自动的返回值呢?
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);
}
}