Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击特定按钮后,摆动帧重叠_Java_Swing_User Interface - Fatal编程技术网

Java 单击特定按钮后,摆动帧重叠

Java 单击特定按钮后,摆动帧重叠,java,swing,user-interface,Java,Swing,User Interface,在完成“登录”页面并单击“登录”按钮后,我的第二个框架出现在“登录”页面的顶部,您仍然可以看到隐藏在下面的组件。为什么单击“登录”按钮后它还没有消失 这是我的密码: public void showLogIn(){ setLayout(new BorderLayout()); setVisible(true); setSize(400,200); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_O

在完成“登录”页面并单击“登录”按钮后,我的第二个框架出现在“登录”页面的顶部,您仍然可以看到隐藏在下面的组件。为什么单击“登录”按钮后它还没有消失

这是我的密码:

public void showLogIn(){
    setLayout(new BorderLayout());
    setVisible(true);
    setSize(400,200);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    logInPanel.setLayout(new GridLayout(2,2,4,4));  
    logInPanel.add(label1);
    logInPanel.add(username);
    logInPanel.add(label2);
    logInPanel.add(password);
    add(logInPanel, BorderLayout.CENTER);
    add(loginBut, BorderLayout.SOUTH);
    loginBut.addActionListener(this);
}

public void showAdminForm(){
    setLayout(new BorderLayout());
    setVisible(true);
    setSize(400,300);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    label3.setText("Logged in as: " + username.getText());
    add(label3, BorderLayout.NORTH);
    buttonPanel.add(createRoom);
    buttonPanel.add(deleteRoom);
    buttonPanel.add(createLect);
    buttonPanel.add(deleteLect);
    buttonPanel.add(showLect);
    buttonPanel.add(logOut);
    add(buttonPanel, BorderLayout.CENTER);
}

在action listener中,我实现了类似于调用showAdminForm的功能;但是我的登录表还在那里。有没有一种方法我不必使用CardLayout

1为了更快地获得更好的帮助,发布一个最小的完整的可验证示例。2有没有一种方法我不必使用cardlayout?你反对使用CardLayout什么?3 setVisibletrue应该是最后完成的操作。4交换设置大小。。对于packSo,如果不使用CardLayout,就无法在showLogIn中隐藏组件?您对使用CardLayout有何异议?如果你误解了,我问这个问题不是为了自娱自乐。我期待一个答案,在我回答其他问题之前会得到一个答案。没关系,我学会了使用卡式布局。谢谢很高兴你把它整理好了。请注意,我们可以并且通常确实为每个GUI使用多个布局。例如,CardLayout可能在两个组件之间翻转,其中一个组件是带有BorderLayout的JPanel。