25/09/2013, 14:18
|
| | Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 10 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);
}
}
|