Java - suma en jtable

 
Vista:

suma en jtable

Publicado por OHAG (2 intervenciones) el 11/08/2009 20:24:13
hola estoy haciendo un programa para sumar matrices utilizo jtable para crear y llenar datos en la matriz pero el resultado no me sale, como pueden ayudarme

int x,y;

for(x=0;x<c;x++)
{
for(y=0;y<f;y++)
{

jtblMat3.setValueAt(jtblMat1.getValueAt(x,y)+jtblMat2.getValueAt(x,y).toString(),x,y);

}
}
}

me despliega el resulado como
11 21 31
11 11 11
23 11 45

deberia de sumar pero no se como hacerlo, alguien que me ayude por favor
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

RE:suma en jtable

Publicado por Juan Manuel Castañeda (50 intervenciones) el 12/08/2009 01:35:04
for(int i=0;i<jtblMat1.getRowCount() || jtblMa2.getRowCount();i++)
for(int j=0;j<jtblMat1.getColumnCount() || j<jtblMat2.getColumnCount();j++){
if(i<jtblMat1.getRowCount() && jtblMa2.getRowCount()){
if(;j<jtblMat1.getColumnCount() && j<jtblMat2.getColumnCount())
jtblMat3.setValueAt(((Long)((int)jtblMat1.getValueAt(i,j)+(int)jtblMat2.getValueAt(i,j))).toString(),i,j);
else
if(;j<jtblMat1.getColumnCount() )
jtblMat3.setValueAt(((Integer)jtblMat1.getValueAt(i,j)).toString(),i,j);
else
jtblMat3.setValueAt(((Integer)jtblMat2.getValueAt(i,j)).toString(),i,j);
}else
if(i<jtblMat1.getRowCount() ){
if(j<jtblMat1.gerColumnCount())
jtblMat3.setValueAt(((Integer)jtblMat1.getValueAt(i,j)).toString(),i,j);
}else
if(j<jtblMat2.getColumnCount())
jtblMat3.setValueAt(((Integer)jtblMat1.getValueAt(i,j)).toString(),i,j);
System.out.println(jtblMat3.getValueAt(i,j));
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar