Java JPanel未显示

Java JPanel未显示,java,swing,Java,Swing,我需要有一个界面准备好,并与可点击的按钮,以显示所有不同的窗口,我们已经创建到目前为止 现在,我的一个团队成员为我们希望用户使用的每个窗口创建了多个JFrame。我们都在NetBeans IDE中工作。我正试图让一个登录窗口弹出,从那里我将使所有的窗口显示时,一个按钮被点击,这应该引导用户到该窗口 以下是我们到目前为止的情况: 主要 用户请求的Login.java中的代码: /* * To change this template, choose Tools | Templates * and

我需要有一个界面准备好,并与可点击的按钮,以显示所有不同的窗口,我们已经创建到目前为止

现在,我的一个团队成员为我们希望用户使用的每个窗口创建了多个JFrame。我们都在NetBeans IDE中工作。我正试图让一个登录窗口弹出,从那里我将使所有的窗口显示时,一个按钮被点击,这应该引导用户到该窗口

以下是我们到目前为止的情况: 主要

用户请求的Login.java中的代码:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Daan
*/
public class Login extends javax.swing.JPanel {

/**
 * Creates new form Login
 */
public Login() {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jPasswordField1 = new javax.swing.JPasswordField();
    jTextField1 = new javax.swing.JTextField();
    jComboBox1 = new javax.swing.JComboBox();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    jLabel1.setIcon(new    javax.swing.ImageIcon("C:\\Users\\Daan\\Dropbox\\HvA\\Programming\\Corendon\\corendon.png")); // NOI18N

    jLabel2.setText("Username");

    jLabel3.setText("Password");

    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Dutch", "English" }));

    jButton1.setText("Login");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("Cancel");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                    .addGap(31, 31, 31)
                    .addComponent(jLabel1))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                    .addGap(45, 45, 45)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(14, 14, 14)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(29, 29, 29)
                            .addComponent(jButton2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1))
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addContainerGap(22, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap(16, Short.MAX_VALUE)
            .addComponent(jLabel1)
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jButton2)
                .addComponent(jButton1))
            .addGap(35, 35, 35))
    );
}// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
}                                        

// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration                   


}
如您所见,我正试图让登录窗口在用户运行程序时显示出来。但我现在要处理的是,如果我将setVisible参数设置为true,它实际上不会显示。该程序实际上只运行1秒,然后停止

这里有什么我做错的吗?在每个类中,我们还没有创建任何事件处理程序。它们只是包含多个组件的窗口。

JPanel需要包装在一个窗口组件(如JFrame)中才能显示

将showLogin方法替换为以下方法:

Login login = new Login();

JFrame frame = new JFrame();
frame.add(login);
frame.pack();
frame.setVisible(true);

在这里显示代码。不是来自imgur。你能分享一下登录类的代码吗?一个旁注。如果您已经介绍了JOptionPane和JDialog,那么您可能需要查看它们。也许会有帮助。
Login login = new Login();

JFrame frame = new JFrame();
frame.add(login);
frame.pack();
frame.setVisible(true);