很简单的,就是通过参数传递的方法!
:
//这是b.java文件
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class b extends JFrame implements ActionListener{
JButton button1=new JButton("显示窗体a");
public b()
{
super("我是窗体b");
this.setBounds(250,80,350,400);
this.setVisible(true);
this.setResizable(false);
button1.setBounds(35,140,70,20);
button1.addActionListener(this);
this.add(button1);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
String title ="我是窗体b传过来的值";
new a(title);
}
}
public static void main(String argv[])
{
new b();
}
}
//这是a.java文件
/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 12-6-19
* Time: 上午7:31
* To change this template use File | Settings | File Templates.
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class a extends JFrame{
JLabel label1 = new JLabel("学号:",JLabel.CENTER);
public a(String parameter)
{
super("我是窗体a");
String str=parameter;
this.setBounds(250,80,350,400);
this.setVisible(true);
this.setResizable(false);
this.add(label1);
label1.setText(parameter);
}
}