JTable con lista enlazada
Publicado por RBustillos (1 intervención) el 24/11/2016 09:25:53
Hola a todos, estoy intentando mostrar en un jTable los datos guardados en una lista enlazada, pero al momento de crear el for para agregar las filas con los datos a la tabla me marca el error "for-each not applicable to expression type", quisiera su ayuda para poder mostrar los datos de la lista en la tabla, las clases que tengo son las siguientes:
Ya no se que hacer y el problema es que tengo que hacer uso de lista enlazada tal como la muestro en mi clase.
Gracias de antemano, saludos.
1
2
3
4
5
6
public class Main {public static void main(String[] args) {
new CrearSolicitud().setVisible(true);
}}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public class Materiales {private int idSolicitud;
private String solicitante;
private String pieza;
private double cantidad;
private String descripcion;
public Materiales(int idSolicitud, String solicitante, String pieza, double cantidad, String descripcion) {
this.idSolicitud = idSolicitud;
this.solicitante = solicitante;
this.pieza = pieza;
this.cantidad = cantidad;
this.descripcion = descripcion;
}public String getDescripcion() {
return descripcion;
}public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}public int getIdSolicitud() {
return idSolicitud;
}public void setIdSolicitud(int idSolicitud) {
this.idSolicitud = idSolicitud;
}public String getSolicitante() {
return solicitante;
}public void setSolicitante(String solicitante) {
this.solicitante = solicitante;
}public String getPieza() {
return pieza;
}public void setPieza(String pieza) {
this.pieza = pieza;
}public double getCantidad() {
return cantidad;
}public void setCantidad(double cantidad) {
this.cantidad = cantidad;
}}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import javax.swing.JOptionPane;
public class Lista {private Nodo inicio;
private Nodo fin;
public Lista() {
inicio = null; fin = null; }public boolean estaVacia() {
if (inicio == null) {
return true;
} else {
return false;
} }void agregarInicio(Materiales ma) {
Nodo actual;
if (this.estaVacia()) {
actual = new Nodo(ma, null);
inicio= actual; fin= actual;} else {
actual= new Nodo(ma, null);
fin.setNext(actual);
fin = actual; } }void mostrar(){
Solicitudes s = new Solicitudes();
if(this.estaVacia()){
JOptionPane.showMessageDialog(null, "¡Esta vacia!");
} else{Nodo temporal;
temporal = inicio;while(temporal!= null){
JOptionPane.showMessageDialog(null,temporal.getDato().toString());
temporal= temporal.getNext();
} } }public int tamaño() {
int contador = 0;Nodo c = this.inicio;
while (c != null) {
contador++;
c = c.getNext();
}System.out.println(""+ contador);
return contador;
}}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class Nodo {private Materiales dato;
private Nodo next;
public Nodo(Materiales dato, Nodo next) {
this.dato = dato;
this.next = next;
}public Materiales getDato() {
return dato;
}public void setDato(Materiales dato) {
this.dato = dato;
}public Nodo getNext() {
return next;
}public void setNext(Nodo next) {
this.next = next;
}}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import javax.swing.JOptionPane;
public class CrearSolicitud extends javax.swing.JFrame {
public static Lista lista = new Lista();
int id = 10000;public CrearSolicitud() {
initComponents();
}public void Limpiar(){
txtCanPie.setText("");
txtDesPie.setText("");
txtNomPie.setText("");
txtNomSol.setText("");
}@SuppressWarnings("unchecked")
private void txtNomSolActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void txtNomPieActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void txtCanPieActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void txtDesPieActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {
if(txtNomSol.getText().isEmpty() || txtNomPie.getText().isEmpty() || txtCanPie.getText().isEmpty() || txtDesPie.getText().isEmpty()){
JOptionPane.showMessageDialog(this, "Llene los campos faltantes");
} else {
String solicitante = txtNomSol.getText();
String pieza = txtNomPie.getText();
int cantidad = Integer.parseInt(txtCanPie.getText());
String descripcion = txtDesPie.getText();
id++;
Materiales m = new Materiales(id, solicitante, pieza, cantidad, descripcion);
lista.agregarInicio(m);
JOptionPane.showMessageDialog(rootPane, "La solicitud se ha creado");
Limpiar();
} }private void btnVerSolActionPerformed(java.awt.event.ActionEvent evt) {
new Solicitudes().setVisible(true);
this.dispose();
} // Variables declaration - do not modify
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnVerSol;
private javax.swing.JLabel lblCanPie;
private javax.swing.JLabel lblDesPie;
private javax.swing.JLabel lblNomPie;
private javax.swing.JLabel lblNomSol;
private javax.swing.JLabel lblSolMat;
private javax.swing.JPanel panelCrearSolicitud;
private javax.swing.JTextField txtCanPie;
private javax.swing.JTextField txtDesPie;
private javax.swing.JTextField txtNomPie;
private javax.swing.JTextField txtNomSol;
// End of variables declaration
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import javax.swing.table.DefaultTableModel;
public class Solicitudes extends javax.swing.JFrame {
public static DefaultTableModel modelo;
public Solicitudes() {
initComponents();
modelo = (DefaultTableModel)tblSolicitudes.getModel();
}@SuppressWarnings("unchecked")
private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {
new CrearSolicitud().setVisible(true);
}private void btnMostarActionPerformed(java.awt.event.ActionEvent evt) {
modelo.getDataVector().clear();
for(Materiales mat: CrearSolicitud.lista) Aquí marca el error
{modelo.addRow(new Object[]{mat.getIdSolicitud(), mat.getSolicitante(), mat.getPieza(), mat.getCantidad(), mat.getDescripcion()});
} } // Variables declaration - do not modify
private javax.swing.JButton btnMostar;
private javax.swing.JButton btnVolver;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblSolicitudes;
private javax.swing.JPanel panelSolicitud;
private javax.swing.JTable tblSolicitudes;
// End of variables declaration
}Ya no se que hacer y el problema es que tengo que hacer uso de lista enlazada tal como la muestro en mi clase.
Gracias de antemano, saludos.
Valora esta pregunta


0