Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/09/2013, 01:12
marcusaurelio
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
applet, mostrar iteracion linea por linea

Hola gente como les va? a mi mas o menos.. termine bapuleado por este applet.. y aca ando pidiendo la escupidera..explico..

la idea.. es con un applet de vaja, claro esta, leer un xls y mostrar la iretacion de esa planilla linea por linea en area de texto..

pero el tema es... que hace todo perfecto.., quiero decir.. abre el xls con la libreria jxl-2.6.3.jar, recorre perfectamente las hojas del libro excel, hasta llegue agusrdar su contenido en base de datos.. y claro por supuesto imprime las lineas en el area de texto.. pero.. no en tiempo real. no se si me explico.. es decir.. espera a terminar de iterar todo el documento y recien ahi.. escribe en el area de texto.

tambien lo probe con bucles for, y while solo y logro lo mismo..

desde ya que todos los jar estan firmados para poder correrlos.

el codigo de mi java es el siguiente..


Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mi_primer_applet;


import java.io.File;
import javax.swing.JFileChooser;
import jxl.Sheet;
import jxl.Workbook;

/**
 *
 * @author Administrador
 */
public class filechooser extends javax.swing.JApplet  {
    
  
    /**
     * Initializes the applet filechooser
     */
    
   
    
    @Override
    public void init() {
        

        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(filechooser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(filechooser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(filechooser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(filechooser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the applet */
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * This method is called from within the init() method to initialize the
     * form. WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField1.setText("jTextField1");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JFileChooser fc = new JFileChooser();
        fc.setCurrentDirectory( new File( "H:/java/" ) );
        
        int opcion = fc.showDialog(this, "Abrir");
        if (opcion == JFileChooser.APPROVE_OPTION) {
            
            File aFile = fc.getSelectedFile();
            String ruta =  aFile.getParent()+"\\";
            String fileName = aFile.getName();    
            //jTextField1.setText(ruta+fileName);
            
            this.filechooser(ruta+fileName);
        }
    }                                        
 
    

  
 public void filechooser(String archivo) {
   
      
      jTextField1.setText(archivo);
        try {
         
            Workbook archivoExcel = Workbook.getWorkbook(new File(archivo));
            //salida+="Número de Hojas\t"+archivoExcel.getNumberOfSheets()+"\n";
            
            for (int sheetNo = 0; sheetNo < archivoExcel.getNumberOfSheets(); sheetNo++) // Recorre 
            // cada    
            // hoja                                                                                                                                                       
            {
                
                
                Sheet hoja = archivoExcel.getSheet(sheetNo);
                int numColumnas = hoja.getColumns();
                int numFilas = hoja.getRows();
               
               
                //salida+="Nombre de la Hoja\t"+ archivoExcel.getSheet(sheetNo).getName()+"\n";
                
                for (int fila = 0; fila < numFilas; fila++) {
                     
                   
                      //System.out.print(newEquals(hoja.getCell(0, fila).getContents(),"proveedor"));
                     
                  
                    String code=hoja.getCell(1, fila).getContents();
                    
                 
                    
                    
                   jTextArea1.append(code+"\r\n");
               
                }
                
          
            }



           // this.gereraTxt(data);
          
        } catch (Exception ioe) {
            //ioe.printStackTrace();
            jTextArea1.append(ioe.toString());
        }
       

    }
 
  
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   

  

   
    
}
agradezco desde ya cualquier ayuda con esto..