- 论坛徽章:
- 0
|
- import java.awt.Container;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class frame1 extends JFrame implements ActionListener
- {
- JButton jb;
- JPanel jp;
- Container con;
- frame1()
- {
- con=getContentPane();
-
- jp=new JPanel();
- jb=new JButton("弹出第二个窗体");
- jb.addActionListener(this);
- jp.add(jb);
- con.add(jp);
- setVisible(true);
- setSize(300,400);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public static void main(String arg[])
- {
- frame1 fl=new frame1();
- }
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- if(e.getSource()==jb)
- {
- frame2 f2=new frame2();
- }
- }
- }
复制代码- import java.awt.Container;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class frame2 extends JFrame{
- JButton jb;
- JPanel jp;
- Container con;
- frame2()
- {
- con=getContentPane();
- jp=new JPanel();
- con.add(jp);
- setVisible(true);
- setSize(300,400);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
复制代码
点了按键。。。选择关闭第二个窗体。。。连第一个也关闭。。。。怎么改?有人会吗? |
|