0

我创建了一个 JFrame,当执行按钮操作时调用第二个 JFrame,该 JFrame 在第一个 JFrame 的构造函数中实例化,并且在此执行的操作中仅 setVisible(true) 但未显示,我不确定我是什么我做错了......在这里我打了我的代码的一小部分:

主框架

public Main() {
    initComponents();
    Datos datos = new Datos();
}

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           

        datos.setVisible(true);
}  

第二帧

public class Datos extends javax.swing.JPanel {

/**
 * Creates new form Datos
 */
public Datos() {
    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() {

    jTextUser = new javax.swing.JTextField();
    jTextPass = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextURL = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jButtonOK = new javax.swing.JButton();
    jButtonCancelar = new javax.swing.JButton();

    jTextUser.setText("jTextField1");

    jTextPass.setText("jTextField2");

    jLabel1.setText("Usuario:");

    jLabel2.setText("Contraseña:");

    jTextURL.setText("jTextField1");
    jTextURL.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextURLActionPerformed(evt);
        }
    });

    jLabel3.setText("URL del repositorio:");

    jButtonOK.setText("OK");

    jButtonCancelar.setText("Cancelar");

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(80, 80, 80)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jLabel3)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jTextURL)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jLabel1))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jTextUser)
                            .add(jTextPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 141, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
            .addContainerGap(92, Short.MAX_VALUE))
        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
            .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jButtonOK)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jButtonCancelar)
            .add(28, 28, 28))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
            .addContainerGap(67, Short.MAX_VALUE)
            .add(jLabel3)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jTextURL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jTextUser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(jLabel1))
            .add(18, 18, 18)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jTextPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(jLabel2))
            .add(51, 51, 51)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jButtonOK)
                .add(jButtonCancelar))
            .add(23, 23, 23))
    );
}// </editor-fold>                        

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

// Variables declaration - do not modify                     
private javax.swing.JButton jButtonCancelar;
private javax.swing.JButton jButtonOK;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextPass;
private javax.swing.JTextField jTextURL;
private javax.swing.JTextField jTextUser;
// End of variables declaration                   

}

4

0 回答 0