Java - Ordenar tabla con el metodo de burbuja en netbeans

 
Vista:
sin imagen de perfil

Ordenar tabla con el metodo de burbuja en netbeans

Publicado por Rodrigo (1 intervención) el 12/06/2014 17:57:48
Hola necesito su ayuda , necesito ordenar mi jtable con el metodo de burbuja ,pero por alguna razon no me sale, aqui paso el codigo y me dicen cual es mi error , porfavor es urgente

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
private void ocultacaptura(java.awt.event.ActionEvent evt) {
captura.setVisible(false);
opcion2.setEnabled(true);
opcion1.setEnabled(true);
DefaultTableModel mimodelo =(DefaultTableModel) tabla.getModel();
int lin=0; int col=0;
 
for(lin=0;lin<=9;lin++)
{
 
ventas.orden(lin);
 
mimodelo.addRow(new Object[lin]);
 
tabla.setValueAt(ventas.obtCodCte(lin),lin,0);
 
tabla.setValueAt(ventas.obtcliente(lin),lin,1);
 
tabla.setValueAt(ventas.obtsubtotal(lin),lin,2);
 
tabla.setValueAt(ventas.obtiva(lin),lin,3);
 
tabla.setValueAt(ventas.obttotal(lin),lin,4);
 
}
}

el meetodo donde agrego las columnas y filas y aqui el metodo de ordenamiento

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
public void orden(int pos)
{
int x, y;
String tmpcte;
int tmpcod ;
float tmpsubtotal;
double tmpiva,tmptotal;
for ( x=0; x <=pos; x++)
{
for( y=0; y<=pos; y++)
{
if( Codcte[y] < Codcte[y+1])
{
tmpcod = Codcte[y+1];
tmpcte = cte[ y + 1 ];
tmpsubtotal = subtotal[ y + 1 ];
tmpiva = iva[ y + 1 ];
tmptotal = total[ y + 1 ];
 
 
Codcte[y +1]= Codcte[y];
cte[ y + 1 ]= cte[y];
subtotal[ y + 1 ]= subtotal[y];
iva[ y + 1 ]= iva[y];
total[ y + 1 ]= total[y];
 
 
Codcte[y]= tmpcod;
cte[ y ]= tmpcte;
subtotal[ y ]= tmpsubtotal;
iva[ y ]= tmpiva;
total[ y ]= tmptotal;
}
 
}
}
 
}

aqui dejo el archivo de netbeans
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder