Foros del Web » Programación para mayores de 30 ;) » Java »

[SOLUCIONADO] applet, mostrar iteracion linea por linea

Estas en el tema de applet, mostrar iteracion linea por linea en el foro de Java en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 25/09/2013, 01:12
 
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..
  #2 (permalink)  
Antiguo 25/09/2013, 02:10
Avatar de chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 19 años, 6 meses
Puntos: 454
Respuesta: applet, mostrar iteracion linea por linea

Hola:

Echa uno ojo a esto para los detalles http://chuwiki.chuidiang.org/index.p...hread)_de_Java

El problema es que en la pulsación del botón haces todo el código de leer el excel y actualizar el textarea. Esa pulsación del botón se ejecuta por defecto en el mismo hilo que repinta la ventanas, por lo que mientras haces todo eso, la ventana y el textarea no se refrescan ni se muestran los resultados que vas escribiendo, sino que se van encolando para mostrarlos cuando el hilo quede libre. Cuando terminas, se muestra todo de golpe. La solución es lanzar un hilo nuevo en el método filechooser() para hacer todo el trabajo pesado en ese hilo separado.

Se bueno.
__________________
Apuntes Java
Wiki de Programación
  #3 (permalink)  
Antiguo 25/09/2013, 12:09
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
Respuesta: applet, mostrar iteracion linea por linea

muchas, muchas, gracias... revisando..
  #4 (permalink)  
Antiguo 25/09/2013, 14:18
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
Respuesta: applet, mostrar iteracion linea por linea

de nuevo gracias por tu ayuda chuidiang, me quedo.. bien..

ahora voy a intentar meterle jtable.. a ver que pasa..

por ahora el codigo me quedo asi.. por ai a alguien le sirve y si ven algo para mejorar.. bienvenido sea

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( "E:/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(final String archivo) {
  
      Runnable miRunnable = new Runnable(){
          
         public void run(){
             
             jTextField1.setText(archivo);
           
            try
            {
              /*inicia rubale*/
                
                  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");
                   jTextField1.setText(code);
               
                }
                
          
            }

Etiquetas: applet, html, iteracion, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:44.