我做了几个窗体,其中一个作为主窗体,在主窗体上有按钮,按的时候子窗体出现,但是我关闭子窗体时主窗体也关闭了,怎么让他关闭子窗体时不会关闭主窗体.我用的JFrame.还有怎么屏蔽主窗体右上角上的关闭按钮.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
public class ZJM implements ActionListener
{
private JButton B1,B2,;
public ZJM (){
JFrame f= new JFrame();
Container contentPane = f.getContentPane();
contentPane.setLayout(new GridLayout(2,1));
B1 =new JButton("会员注册");
B2 =new JButton("会员信息查询");
contentPane.add(B1);
contentPane.add(B2);
B1.addActionListener(this);
B2.addActionListener(this);
f.setTitle("网吧管理系统");
f.pack();
f.setSize(250,250);
f.setBounds(410,180,250,200);
f.setVisible(true);
}
public void actionPerformed (ActionEvent e) {
if (e.getSource()==B1)
new HYZC();
else if(e.getSource()==B2)
new HYXXCX();
}
public static void main(String[] args) {
new ZJM();
}
}
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import javax.swing.JFrame;
public class HYXXCX extends WindowAdapter implements ActionListener {
private JFrame f;
private JButton B1;
private JLabel L1,L2,L3,L4,L5,L6,L7,L8,L9;
private JTextField T1,T3,T4,T5,T6,T7,T8;
private JPasswordField T2;
public HYXXCX(){
f= new JFrame();
f.setTitle("会员信息查询");
Container contentPane = f.getContentPane();
contentPane.setLayout(null);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
f.setBounds(300,130,440,500);
f.setVisible(true);
B1 =new JButton(" 查询 ");
L1=new JLabel("会员号码:");
L2=new JLabel("会员密码:");
L3=new JLabel("身份证号码:");
L4=new JLabel("姓名:");
L5=new JLabel("性别:");
L6=new JLabel("电话:");
L7=new JLabel("住址:");
L8=new JLabel("余额");
L9=new JLabel("查询结果:");
T1 =new JTextField(50);
T2 =new JPasswordField(50);
T3 =new JTextField(50);
T4 =new JTextField(50);
T5 =new JTextField(50);
T6 =new JTextField(50);
T7 =new JTextField(50);
T8 =new JTextField(50);
f.add(L1);
L1.setBounds(40,40,70,25);
f.add(T1);
T1.setBounds(130,40,160,25);
f.add(L2);
L2.setBounds(40,80,70,25);
f.add(T2);
T2.setBounds(130,80,160,25);
f.add(L9);
L9.setBounds(40,120,70,25);
f.add(L3);
L3.setBounds(40,170,70,25);
f.add(T3);
T3.setBounds(130,170,250,25);
f.add(L4);
L4.setBounds(40,210,70,25);
f.add(T4);
T4.setBounds(130,210,250,25);
f.add(L5);
L5.setBounds(40,250,70,25);
f.add(T5);
T5.setBounds(130,250,250,25);
f.add(L6);
L6.setBounds(40,290,70,25);
f.add(T6);
T6.setBounds(130,290,250,25);
f.add(L7);
L7.setBounds(40,330,70,25);
f.add(T7);
T7.setBounds(130,330,250,25);
f.add(L8);
L8.setBounds(40,370,70,25);
f.add(T8);
T8.setBounds(130,370,250,25);
f.add(B1);
B1.setBounds(300,70,80,30);
B1.addActionListener(this);
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void actionPerformed (ActionEvent e) {
}
}
这是一个子窗体