Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 24th, 2012  |  syntax: Java  |  size: 1.01 KB  |  hits: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  public void calcula_total(JTable Tabla ,JTextField jtotal,int a){
  2.    
  3.         try{
  4.            
  5. //a = es la posicion dela columna del jtable que quieres sumar;
  6.        
  7.         double acum = 0;
  8.        
  9.         for (int i = 0; i <= Tabla.getRowCount() -1; i++){
  10.  
  11.             String t = String.valueOf(Tabla.getValueAt(i, a));                    
  12.        
  13.             double tv = Double.parseDouble(t);
  14.              
  15.        
  16.             acum =  acum+tv;
  17.            
  18.         }
  19.    
  20.         jtotal.setText("$ "+numerico(acum)+" ");
  21.  
  22.          }catch(Exception e){
  23.            
  24.             System.out.println(e);
  25.         }
  26.        
  27.        
  28.         }    
  29.  
  30.  
  31. public String numerico(double numero){
  32.        
  33.         NumberFormat[] nfa = new NumberFormat[1];
  34.         nfa[0] = NumberFormat.getInstance();
  35.         String respuesta="";
  36.  
  37.         for (NumberFormat nf : nfa) {
  38.             respuesta = (String)nf.format(numero);
  39.         }
  40.        
  41.        
  42.         return respuesta;
  43.        
  44.        
  45.     }