很简单的:
你看看符合要求么:
//这是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)
{
this.setVisible(false);
new a();
}
}
public static void main(String argv[])
{
new b();
}
}
//这是a.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class a extends JFrame{
JLabel label1 = new JLabel("我是窗体a",JLabel.CENTER);
public a()
{
super("我是窗体a");
this.setBounds(100,80,200,100);
this.setVisible(true);
this.setResizable(false);
this.add(label1);
}
}
给按钮添加一个事件 通过对按钮上的文字判断 来劲行相应的界面调用