import java.awt.*;
import java.awt.event.*;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class button extends JFrame{
public button(){
JButton button=new JButton("查找");
setLayout(new FlowLayout());
add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
selectinterface sl = new selectinterface();
sl.setVisible(true);
sl.pack();
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
button frame=new button();
frame.setTitle("按钮");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,600);
frame.setVisible(true);
}
}
class selectinterface extends JFrame{
public selectinterface(){
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(9,2,5,5));
p1.add(new JLabel("编号"));
p1.add(new JTextField(6));
p1.add(new JLabel("姓名"));
p1.add(new JTextField(8));
p1.add(new JLabel("性别"));
p1.add(new JTextField(1));
p1.add(new JLabel("年龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("职位"));
p1.add(new JTextField(20));
p1.add(new JLabel("学历"));
p1.add(new JTextField(4));
p1.add(new JLabel("学位"));
p1.add(new JTextField(4));
p1.add(new JLabel("工龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("工资等级"));
p1.add(new JTextField(2));
JPanel p2=new JPanel();
p2.add(new JButton("确定"));
p2.add(new JButton("取消"));
setLayout(new GridLayout(2,1,0,100));
add(p1);
add(p2);
}
}
先用eclipse的界面设计器设计好你要用的两个界面
然后在主界面的一个button上添加一个单击事件在事件的处理代码中产生一个界面2的类并且将该对象的可视化属性设置为可见即可