importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassTestextendsJFrameimplementsActionListener{JButtonjb1,jb2;JTextFieldjt1,jt2;publicstaticvoidmain(Str...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame implements ActionListener {
JButton jb1, jb2;
JTextField jt1,jt2;
public static void main(String args[]) {
Test ts = new Test();
}
public Test() {
jb1 = new JButton("添加");
jb1.addActionListener(this);
jt1=new JTextField(10);
this.setLayout(new FlowLayout());
this.add(jt1);
this.add(jb1);
this.setSize(250, 200);
this.setLocationRelativeTo(this);// 设置窗口居中
this.setTitle("通讯录");// 设置标题
this.setVisible(true);// 设置可见
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 退出设置
this.setResizable(false);
}
public void jf2() {
final JFrame jf = new JFrame();
jb2 = new JButton("传送");
jb2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jf.setVisible(false);
}
});
jt2=new JTextField(10);
jf.setLayout(new FlowLayout());
jf.add(jt2);
jf.add(jb2);
jf.setSize(250, 100);
jf.setLocationRelativeTo(this);// 设置窗口居中
jf.setTitle("通讯录");// 设置标题
jf.setVisible(true);// 设置可见
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);// 退出设置
jf.setResizable(false);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb1) {
jf2();
}
}
}
谢谢各位了,麻烦大家帮忙下
展开