//Aquí guardo los datos ingresados por teclado
private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {
if (txtNombre.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Por favor ingrese el nombre");
return;
}
if (txtApellidos.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Por favor ingrese los apellidos");
return;
}
if (txtRut.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Por favor ingrese el RUT");
return;
}
if (txtValidador.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Por favor ingrese el código validador");
return;
}
if (txtEmail.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Por favor ingrese el email");
return;
}
if (txtTelefono.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Por favor ingrese el teléfono");
return;
}
String Nombre, Apellidos, Rut, Email, Telefono;
Nombre = txtNombre.getText();
Apellidos = txtApellidos.getText();
Rut = txtRut.getText();
Email = txtEmail.getText();
Telefono = txtTelefono.getText();
Persona persona = new Persona(Nombre, Apellidos, Rut, Email, Telefono);
agenda.GuardarPersona(persona);
//Se guardan en esta agenda
public class Agenda {
Vector vector = new Vector();
Persona persona = new Persona();
public void GuardarPersona(Persona persona) {
if (vector.add(persona)) {
JOptionPane.showMessageDialog(null, "Se ha agregado correctamente la persona");
}
}
//Y finalmente llamo a este metodo pero los datos me salen en null
public String MostrarAgenda() {
String Linea = "", Linea2;
for (int x = 0; x < vector.size(); x++) {
persona = (Persona) vector.get(x);
Linea2 =" Nombre: "+ persona.Nombre + " \n " +"Apellido.: "+ persona.Apellidos + " \n " +"Rut.........: "+ persona.Rut + " \n "+"Telefono: " + persona.Telefono;
Linea = Linea + Linea2 + "\n";
}
return Linea;
}
}
@Franco Rolando imagine you mean this class
public class Persona {
public String Nombre;
public String Apellidos;
public String Rut;
public String Telefono;
public Persona() {
}
public Persona(String Nombre, String Apellidos, String Rut, String Email, String Telefono) {