I am trying to make a program that reads a text file, it must be printed on screen in some defined fields, I must configure a button of first, next, previous and last. I'm with the next but I try to do it through a cycle as if it were an array but I can not get ahead every time I press the button. public static void main (String [] args) { JFrame v_frame = new JFrame (); v_frame.setSize (500, 500); v_frame.setLayout (null);
JLabel lb_nombre = new JLabel("Nombre:");
lb_nombre.setBounds(50, 50, 80, 30);
v_frame.add(lb_nombre);
JLabel lb_cedula = new JLabel("Cedula:");
lb_cedula.setBounds(50, 100, 100, 30);
v_frame.add(lb_cedula);
JLabel lb_edad = new JLabel("Edad:");
lb_edad.setBounds(50, 150, 200, 30);
v_frame.add(lb_edad);
v_nombre.setBounds(150, 50, 200, 30);
v_frame.add(v_nombre);
v_cedula.setBounds(150, 100, 200, 30);
v_frame.add(v_cedula);
v_edad.setBounds(150, 150, 200, 30);
v_frame.add(v_edad);
v_modelo.addColumn("Nombre: ");
v_modelo.addColumn("Cedula: ");
v_modelo.addColumn("Edad: ");
v_tabla.setBounds(50, 250, 400, 140);
v_tabla.setVisible(true);
v_frame.add(v_tabla);
JButton bt_salir = new JButton();
bt_salir.setText("Salir");
bt_salir.setBounds(400, 400, 80, 30);
bt_salir.setVisible(true);
v_frame.add(bt_salir);
bt_salir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
JButton bt_primero = new JButton();
bt_primero.setText("Primero");
bt_primero.setBounds(20, 200, 80, 30);
bt_primero.setVisible(true);
v_frame.add(bt_primero);
bt_primero.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
leer();
primero(v_modelo);
}
});
JButton bt_Siguiente = new JButton();
bt_Siguiente.setText("Siguiente");
bt_Siguiente.setBounds(110, 200, 100, 30);
bt_Siguiente.setVisible(true);
v_frame.add(bt_Siguiente);
bt_Siguiente.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
leer();
siguiente();
}
});
JButton bt_ante = new JButton();
bt_ante.setText("Anterior");
bt_ante.setBounds(220, 200, 100, 30);
bt_ante.setVisible(true);
v_frame.add(bt_ante);
bt_ante.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
leer();
}
});
JButton bt_ulti = new JButton();
bt_ulti.setText("Ultimo");
bt_ulti.setBounds(330, 200, 100, 30);
bt_ulti.setVisible(true);
v_frame.add(bt_ulti);
bt_ulti.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
leer();
}
});
v_frame.setVisible(true);
}
Code for the following button: public static void next () {
try {
FileReader v_lector = new FileReader(v_ruta_archivo);
BufferedReader mi_buffer = new BufferedReader(v_lector);
String v_linea;
while ((v_linea = mi_buffer.readLine()) != null) {
String v_arreglo[] = v_linea.split(",");
Object[] v_temporal = {v_arreglo[0], v_arreglo[1], v_arreglo[2]};
int lim = v_arreglo.length;
for (int i = 0; i < lim - 2; i++) {
for (int j = 0; j < i + 1; j++) {
String linea1 = (String) v_modelo.getValueAt(i, 0);
String linea2 = (String) v_modelo.getValueAt(i, 1);
String linea3 = (String) v_modelo.getValueAt(i, 2);
v_nombre.setText(linea1);
v_cedula.setText(linea2);
v_edad.setText(linea3);
}
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error de Lectura", "Error", 0);
}
}
}
I wanted to use the file as if it were an array, or trying to transform it from a JTable to an Array for handling, but I'm lost, some suggestions please.
Thank you