
Untitled
By: a guest on
Sep 24th, 2012 | syntax:
Java | size: 1.01 KB | hits: 35 | expires: Never
public void calcula_total(JTable Tabla ,JTextField jtotal,int a){
try{
//a = es la posicion dela columna del jtable que quieres sumar;
double acum = 0;
for (int i = 0; i <= Tabla.getRowCount() -1; i++){
String t = String.valueOf(Tabla.getValueAt(i, a));
double tv = Double.parseDouble(t);
acum = acum+tv;
}
jtotal.setText("$ "+numerico(acum)+" ");
}catch(Exception e){
System.out.println(e);
}
}
public String numerico(double numero){
NumberFormat[] nfa = new NumberFormat[1];
nfa[0] = NumberFormat.getInstance();
String respuesta="";
for (NumberFormat nf : nfa) {
respuesta = (String)nf.format(numero);
}
return respuesta;
}