Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. en agragr jugador interfase
  2. private void jbtnAbrirActionPerformed(java.awt.event.ActionEvent evt) {
  3. int i;
  4. if (Persistencia.agregarJugadores(jFileChooser1.getSelectedFile(), s, false)) {
  5. i = JOptionPane.showConfirmDialog(this, "Hay jugadores con mismo alias, desea actualizar los jugadores?.", "Actualizar?.", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
  6. if (i == JOptionPane.YES_OPTION) {
  7. Persistencia.actualizarJugadores(jFileChooser1.getSelectedFile(), s);
  8. JOptionPane.showMessageDialog(this, "Se han actualizado los jugadores. ", "Jugadores Actualizados.", JOptionPane.INFORMATION_MESSAGE);
  9. } else if (i == JOptionPane.NO_OPTION) {
  10. JOptionPane.showMessageDialog(this, "No se actualizo ", "Nope.", JOptionPane.INFORMATION_MESSAGE);
  11. }
  12. } else {
  13. JOptionPane.showMessageDialog(this, "Se han agregado los jugadores. ", "Jugadores Agregados.", JOptionPane.INFORMATION_MESSAGE);
  14. }
  15. }
  16.  
  17.  
  18.  
  19. en clase persistencia
  20.  
  21. public static void actualizarJugadores(File archivo, Sistema s) {
  22. ArchivoLectura al1 = new ArchivoLectura(archivo.getPath());
  23.  
  24. while (al1.hayMasLineas()) {
  25. String lineaActual = al1.linea();
  26. String[] contenido = lineaActual.split("@");
  27. Jugador j = new Jugador();
  28. j.setNombre(contenido[0]);
  29. j.setAlias(contenido[1]);
  30. int edad;
  31. edad = Integer.parseInt(contenido[2]);
  32. j.setEdad(edad);
  33. for (int i = 0; i < s.getJugadores().size(); i++) {
  34. if (s.getJugadores().get(i).getAlias().equals(j.getAlias())) {
  35. s.getJugadores().get(i).setNombre(j.getNombre());
  36. s.getJugadores().get(i).setEdad(j.getEdad());
  37. }
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement