JAVA中GUI界面运行时只出图标无界面,无报错内容。

一、登录界面
package GUI; //登录界面
public class loginwindow extends JFrame implements ActionListener,WindowListener {
//创建组件
JButton log_btn = new JButton("登录");
JButton reg_btn = new JButton("注册");
JButton cancel_btn = new JButton("取消");
JButton out_btn = new JButton("退出");

JTextField name_txt = new JTextField(15);
JPasswordField psw_txt = new JPasswordField(15);

JLabel title_jlb = new JLabel("欢迎使用园博园景区管理系统");
JLabel name_jlb = new JLabel("用户名:");
JLabel psw_jlb = new JLabel("密     码:");

//创建面板
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p21 = new JPanel();
JPanel p22 = new JPanel();

public loginwindow() throws ClassNotFoundException{
    //注册数据库驱动
    GetConn.get();
    //设置窗口属性
    this.setVisible(true);
    this.setSize(1000, 1000);
    this.setLocation(600, 1000);
    this.setTitle("登录窗口");
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    
    //改变窗口布局为网格布局
    this.setLayout(new GridLayout(4,1));
    
    //添加组件
    p1.add(title_jlb);
    this.add(p1);
    p2.setLayout(new GridLayout(2,1));
    p2.add(p21);
    p2.add(p22);
    p21.add(name_jlb);
    p21.add(name_txt);
    p22.add(psw_jlb);
    p22.add(psw_txt);
    this.add(p2);
    p3.add(log_btn);
    p3.add(reg_btn);
    p3.add(cancel_btn);
    p3.add(out_btn);
    this.add(p3);
    
    //设置监听
    log_btn.addActionListener(this);
    reg_btn.addActionListener(this);
    cancel_btn.addActionListener(this);
    out_btn.addActionListener(this);
}

@Override
public void windowOpened(WindowEvent e) {
    // TODO Auto-generated method stub
    
}

@Override
public void windowClosing(WindowEvent e) {
    // TODO Auto-generated method stub
    int a = JOptionPane.showConfirmDialog(null, "真的要退出吗?", "确认退出!", JOptionPane.YES_NO_CANCEL_OPTION);
    if(a==0) {
        System.exit(0);
    }else {
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }
}

@Override
public void windowClosed(WindowEvent e) {
    // TODO Auto-generated method stub
    
}

@Override
public void windowIconified(WindowEvent e) {
    // TODO Auto-generated method stub
    
}

@Override
public void windowDeiconified(WindowEvent e) {
    // TODO Auto-generated method stub
    
}

@Override
public void windowActivated(WindowEvent e) {
    // TODO Auto-generated method stub
    
}

@Override
public void windowDeactivated(WindowEvent e) {
    // TODO Auto-generated method stub
    
}

@Override
public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    //设置按钮属性并实现跳转页面,点击按钮获取的事件
    if(e.getSource()==reg_btn) {
        new Welcome();
        this.dispose();
    }else if(this.name_txt.getText().equals("admin")&&(new String(psw_txt.getPassword()).equals("123456"))) {
        new Welcome();
        this.dispose();
    }else {
        JOptionPane.showInputDialog(null, "用户名或密码");
        name_txt.setText("");
        psw_txt.setText("");
    }
    
    if(e.getActionCommand().equalsIgnoreCase("退出")) {
        int a = JOptionPane.showConfirmDialog(null, "真的要退出吗?", "确认退出!", JOptionPane.YES_NO_CANCEL_OPTION);
        if(a==0) {
            System.exit(0);
        }else {
            this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//不退出
        }
    }
}

}
二、界面测试类
package TEST; //界面测试类
import GUI.loginwindow;
public class GUI {
public static void main(String[] args) {
try {
loginwindow myloginwindow = new loginwindow();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
}
}
}

布局有问题,窗口默认布局是BorderLayout,p2覆盖了p1,p3覆盖了p2,p3是空白的,所以没有内容显示。