2014-02-18 30 views
-2

嗨,我試圖從主框架中選擇行的值在Jdialog中打印。 我試着這樣做,但是當我在主框架中調用方法(「m.SetRecoger)時,它顯示此錯誤:參數數組字符串Jframe

」方法SetRecoger類Modificar不能應用於給定的類型; 需要:字符串[] 發現:沒有參數 理由:實際的和正式的參數列表的長度不同」

的完整代碼:

主框架,其中i有JTable的: 公共類DniFrame延伸的javax .swing.JFrame {

/** 
* Creates new form DniFrame 
*/ 
public DniFrame() { 

    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() { 

    jPanel1 = new javax.swing.JPanel(); 
    jScrollPane2 = new javax.swing.JScrollPane(); 
    jTable2 = new javax.swing.JTable(); 
    jButton1 = new javax.swing.JButton(); 
    jMenuBar1 = new javax.swing.JMenuBar(); 
    jMenu1 = new javax.swing.JMenu(); 
    jMenuItem1 = new javax.swing.JMenuItem(); 
    jMenu2 = new javax.swing.JMenu(); 
    jMenuItem2 = new javax.swing.JMenuItem(); 
    jMenuItem4 = new javax.swing.JMenuItem(); 
    jMenuItem3 = new javax.swing.JMenuItem(); 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
    addWindowListener(new java.awt.event.WindowAdapter() { 
     public void windowOpened(java.awt.event.WindowEvent evt) { 
      formWindowOpened(evt); 
     } 
    }); 

    jTable2.setModel(new javax.swing.table.DefaultTableModel(
     new Object [][] { 
      {null, null, null, null}, 
      {null, null, null, null}, 
      {null, null, null, null}, 
      {null, null, null, null} 
     }, 
     new String [] { 
      "Nif", "Nom", "Cognoms", "Telefon" 
     } 
    )); 
    jScrollPane2.setViewportView(jTable2); 

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

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
    jPanel1.setLayout(jPanel1Layout); 
    jPanel1Layout.setHorizontalGroup(
     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(jPanel1Layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
       .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE) 
       .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
      .addContainerGap()) 
    ); 
    jPanel1Layout.setVerticalGroup(
     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(jPanel1Layout.createSequentialGroup() 
      .addContainerGap() 
      .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
      .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
    ); 

    jMenu1.setText("Aplicació"); 

    jMenuItem1.setText("Sortir"); 
    jMenuItem1.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jMenuItem1ActionPerformed(evt); 
     } 
    }); 
    jMenu1.add(jMenuItem1); 

    jMenuBar1.add(jMenu1); 

    jMenu2.setText("Base de Dades"); 
    jMenu2.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jMenu2ActionPerformed(evt); 
     } 
    }); 

    jMenuItem2.setText("Afegir"); 
    jMenuItem2.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jMenuItem2ActionPerformed(evt); 
     } 
    }); 
    jMenu2.add(jMenuItem2); 

    jMenuItem4.setText("Modificar"); 
    jMenuItem4.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jMenuItem4ActionPerformed(evt); 
     } 
    }); 
    jMenu2.add(jMenuItem4); 

    jMenuItem3.setText("Eliminar"); 
    jMenuItem3.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jMenuItem3ActionPerformed(evt); 
     } 
    }); 
    jMenu2.add(jMenuItem3); 

    jMenuBar1.add(jMenu2); 

    setJMenuBar(jMenuBar1); 

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    getContentPane().setLayout(layout); 
    layout.setHorizontalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
    ); 
    layout.setVerticalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
    ); 

    pack(); 
}// </editor-fold>       

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

    dispose(); 


}           

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {           
    new afegir(this, true).setVisible(true); 


}           

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {           
modify(); 
Modificar m=new Modificar(this, true); 
m.SetRecoger(); 
new Modificar(this, true).setVisible(true); 


}           

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

    DefaultTableModel modelo = (DefaultTableModel) this.jTable2.getModel(); 
    int i = jTable2.getSelectedRow(); 

    if (i == -1) { 
     JOptionPane.showMessageDialog(null, "Debes selecioonar una fila"); 

    } else { 

     int ax = JOptionPane.showConfirmDialog(null, "Estás seguro de que quieres eliminar este registro?"); 
     if (ax == JOptionPane.YES_OPTION) { 
      JOptionPane.showMessageDialog(null, "Has seleccionado SI."); 

      String dni = (String) jTable2.getValueAt(i, 0); 
      modelo.removeRow(jTable2.getSelectedRow()); 

     try { 
      Class.forName("com.mysql.jdbc.Driver"); 
      try (Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24")) { 
       Statement comando = conexion.createStatement(); 
       comando.executeUpdate("delete from dades_pers where nif = '" + dni + "'"); 
      } 
      JOptionPane.showMessageDialog(null, "Registro borrado"); 
     } catch (ClassNotFoundException e) { 
      JOptionPane.showMessageDialog(null, "No se ha podido eliminar el registro"); 

     } catch (SQLException ex) { 
      Logger.getLogger(DniFrame.class.getName()).log(Level.SEVERE, null, ex); 
     } 






     } else if (ax == JOptionPane.NO_OPTION) { 
      JOptionPane.showMessageDialog(null, "Has seleccionado NO."); 
     } 



    } 


}           

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

    try { 

     Class.forName("com.mysql.jdbc.Driver"); 
     Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24"); 
     Statement comando = conexion.createStatement(); 
     ResultSet result = comando.executeQuery("select * from dades_pers"); 
     ResultSetMetaData rsMD = result.getMetaData(); 
     int numcolumnas = rsMD.getColumnCount(); 
     DefaultTableModel modelo = new DefaultTableModel(); 
     this.jTable2.setModel(modelo); 

     for (int x = 1; x <= numcolumnas; x++) { 
      modelo.addColumn(rsMD.getColumnLabel(x)); 

     } 

     while (result.next()) { 
      Object[] fila = new Object[numcolumnas]; 
      for (int i = 0; i < numcolumnas; i++) { 
       fila[i] = result.getObject(i + 1); 
      } 
      modelo.addRow(fila); 

     } 

    } catch (ClassNotFoundException e) { 
    } catch (SQLException sqe) { 
    } 

// TODO此處添加您的處理代碼: }

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

private void formWindowOpened(java.awt.event.WindowEvent evt) {         

    añadirTabla(); 


}         

public void añadirTabla() { 

    try { 

     Class.forName("com.mysql.jdbc.Driver"); 
     Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24"); 
     Statement comando = conexion.createStatement(); 
     ResultSet result = comando.executeQuery("select * from dades_pers"); 
     ResultSetMetaData rsMD = result.getMetaData(); 
     int numcolumnas = rsMD.getColumnCount(); 
     DefaultTableModel modelo = new DefaultTableModel(); 
     this.jTable2.setModel(modelo); 

     for (int x = 1; x <= numcolumnas; x++) { 
      modelo.addColumn(rsMD.getColumnLabel(x)); 

     } 

     while (result.next()) { 
      Object[] fila = new Object[numcolumnas]; 
      for (int i = 0; i < numcolumnas; i++) { 
       fila[i] = result.getObject(i + 1); 
      } 
      modelo.addRow(fila); 

     } 

    } catch (ClassNotFoundException e) { 
    } catch (SQLException sqe) { 
    } 

} 

public String [] modify() { 

    String[] registros = new String[4]; 
    int i = jTable2.getSelectedRow(); 

    if (i == -1) { 
     JOptionPane.showMessageDialog(null, "Debes selecioonar una fila"); 
     new Modificar(this, true).setVisible(false); 
    } else { 

     registros[0] = (String) jTable2.getValueAt(i, 0).toString(); 
     registros[1] = (String) jTable2.getValueAt(i, 1).toString(); 
     registros[2] = (String) jTable2.getValueAt(i, 2).toString(); 
     registros[3] = (String) jTable2.getValueAt(i, 3).toString(); 
    } 
    return registros; 
} 

/** 
* @param args the command line arguments 
*/ 
public static void main(String args[]) { 
    /* Set the Nimbus look and feel */ 
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 
    * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
    */ 
    try { 
     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
      if ("Nimbus".equals(info.getName())) { 
       javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
       break; 
      } 
     } 
    } catch (ClassNotFoundException ex) { 
     java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (InstantiationException ex) { 
     java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (IllegalAccessException ex) { 
     java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
     java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } 
    //</editor-fold> 

    /* Create and display the form */ 
    java.awt.EventQueue.invokeLater(new Runnable() { 
     public void run() { 
      new DniFrame().setVisible(true); 
     } 
    }); 

} 

// Variables declaration - do not modify      
private javax.swing.JButton jButton1; 
private javax.swing.JMenu jMenu1; 
private javax.swing.JMenu jMenu2; 
private javax.swing.JMenuBar jMenuBar1; 
private javax.swing.JMenuItem jMenuItem1; 
private javax.swing.JMenuItem jMenuItem2; 
private javax.swing.JMenuItem jMenuItem3; 
private javax.swing.JMenuItem jMenuItem4; 
private javax.swing.JPanel jPanel1; 
private javax.swing.JScrollPane jScrollPane2; 
private javax.swing.JTable jTable2; 
// End of variables declaration     

}

// the jdialog(the second frame);

公共類Modificar擴展javax.swing.JDialog中的{

private DniFrame p; 

/** 
* Creates new form Modificar 
*/ 
public Modificar(java.awt.Frame parent, boolean modal) { 
    super(parent, modal); 
    this.p= (DniFrame)parent; 
    initComponents(); 
} 


public void SetRecoger(String[] v) { 
    String nif = v[0]; 
    String nom = v[1]; 
    String cognom =v[2]; 
    String tel = v[3]; 

String []datos ={nif,nom,cognom,tel}; 

    jTextField5.setText(nif); 
    jTextField6.setText(nom); 
    jTextField7.setText(cognom); 
    jTextField8.setText(tel); 


} 

/** 
* 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() { 

    jPanel2 = new javax.swing.JPanel(); 
    jLabel5 = new javax.swing.JLabel(); 
    jTextField5 = new javax.swing.JTextField(); 
    jTextField6 = new javax.swing.JTextField(); 
    jTextField7 = new javax.swing.JTextField(); 
    jTextField8 = new javax.swing.JTextField(); 
    jLabel6 = new javax.swing.JLabel(); 
    jLabel7 = new javax.swing.JLabel(); 
    jLabel8 = new javax.swing.JLabel(); 
    jButton2 = new javax.swing.JButton(); 
    jButton3 = new javax.swing.JButton(); 
    jPanel1 = new javax.swing.JPanel(); 
    jLabel1 = new javax.swing.JLabel(); 

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 

    jLabel5.setText("Nom"); 

    jTextField5.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jTextField5ActionPerformed(evt); 
     } 
    }); 

    jTextField6.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jTextField6ActionPerformed(evt); 
     } 
    }); 

    jTextField7.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jTextField7ActionPerformed(evt); 
     } 
    }); 

    jTextField8.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jTextField8ActionPerformed(evt); 
     } 
    }); 

    jLabel6.setText("NIF"); 

    jLabel7.setText("Cognoms"); 

    jLabel8.setText("Telefon"); 

    jButton2.setText("Desar les dades"); 
    jButton2.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jButton2ActionPerformed(evt); 
     } 
    }); 

    jButton3.setText("Tancar"); 
    jButton3.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jButton3ActionPerformed(evt); 
     } 
    }); 

    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Estat")); 

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
    jPanel1.setLayout(jPanel1Layout); 
    jPanel1Layout.setHorizontalGroup(
     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 
      .addContainerGap() 
      .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
      .addContainerGap()) 
    ); 
    jPanel1Layout.setVerticalGroup(
     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 
      .addContainerGap() 
      .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE) 
      .addContainerGap()) 
    ); 

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); 
    jPanel2.setLayout(jPanel2Layout); 
    jPanel2Layout.setHorizontalGroup(
     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(jPanel2Layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) 
       .addGroup(jPanel2Layout.createSequentialGroup() 
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
         .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)) 
        .addGap(31, 31, 31) 
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
         .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))) 
       .addGroup(jPanel2Layout.createSequentialGroup() 
        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addGap(78, 78, 78) 
        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)) 
       .addGroup(jPanel2Layout.createSequentialGroup() 
        .addGap(10, 10, 10) 
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 
      .addContainerGap(23, Short.MAX_VALUE)) 
    ); 
    jPanel2Layout.setVerticalGroup(
     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(jPanel2Layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addGap(17, 17, 17) 
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addGap(15, 15, 15) 
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addGap(18, 18, 18) 
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addGap(18, 18, 18) 
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
       .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
    ); 

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    getContentPane().setLayout(layout); 
    layout.setHorizontalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
      .addContainerGap() 
      .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
      .addContainerGap()) 
    ); 
    layout.setVerticalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addGap(0, 10, Short.MAX_VALUE)) 
    ); 

    pack(); 
}// </editor-fold>       

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


}           

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

}           

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

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


}           

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

    try { 

     Class.forName("com.mysql.jdbc.Driver"); 
    } catch (ClassNotFoundException ex) { 
     Logger.getLogger(afegir.class.getName()).log(Level.SEVERE, null, ex); 
    } 

    try { 
     Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24"); 

     Statement comando = conexion.createStatement(); 

     String nif = jTextField5.getText(); 
     String nom = jTextField6.getText(); 
     String cognom = jTextField7.getText(); 
     String tel = jTextField8.getText(); 


     comando.executeUpdate("UPDATE dades_pers SET nom= '" + nom + "',cognoms='" + cognom + "',telefon= '" + tel + "' where nif= '" + nif + "'"); 
     conexion.close(); 
     jLabel1.setText("Datos Modificados correctamente"); 

    } catch (Exception e) { 
     JOptionPane.showMessageDialog(null, "Error al modificar los datos" + e); 

    } 


}           

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {           
    dispose(); 
}           

//

/** 
* @param args the command line arguments 
*/ 
public static void main(String args[]) { 
    /* Set the Nimbus look and feel */ 
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 
    * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
    */ 
    try { 
     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
      if ("Nimbus".equals(info.getName())) { 
       javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
       break; 
      } 
     } 
    } catch (ClassNotFoundException ex) { 
     java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (InstantiationException ex) { 
     java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (IllegalAccessException ex) { 
     java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
     java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } 
    //</editor-fold> 

    /* Create and display the dialog */ 
    java.awt.EventQueue.invokeLater(new Runnable() { 
     public void run() { 
      Modificar dialog = new Modificar(new javax.swing.JFrame(), true); 
      dialog.addWindowListener(new java.awt.event.WindowAdapter() { 
       @Override 
       public void windowClosing(java.awt.event.WindowEvent e) { 
        System.exit(0); 
       } 
      }); 
      dialog.setVisible(true); 
     } 
    }); 

} 

// Variables declaration - do not modify      

謝謝!

+4

爲了更好地幫助更快,發佈[MCTaRE(http://stackoverflow.com/help/mcve)(最小完整測試和可讀例子)。 –

+0

順便說一句 - 沒有人在他們正確的思想中將通過655行代碼(這是太長,不能使用標準代碼格式)尋找錯誤。縮小範圍! –

+0

@AndrewThompson必須留在我的左腦中:P但我同意你的看法......只是在滾動時碰巧跳到我身邊 –

回答

1

您正在調用DniFrame中的方法SetRecoger,而不傳遞任何參數給方法。

您在Modificar對話框中定義的方法需要一個字符串數組作爲參數。

public void SetRecoger(String[] v) {....} 

由於您modify()方法返回一個字符串數組,試試這個:

String[] mod = modify(); 
Modificar m = new Modificar(this, true); 
m.SetRecoger(mod); 
new Modificar(this, true).setVisible(true);