Beh non lo avevo postato perchè il codice del Jframe, il Jpanel e la jTextArea erano stati aggiunti da netbeans in automatico mentre creavo nella scheda "design"...cmq il codice completo è questo qui sotto...ho creato un altro metodo (setAggiungi) in modo da poter utilizzare jTextArea con il metodo getValori.....nel debug sembra funzionare..ma poi non mi scrive nulla all'interno della text
codice:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bird;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.LabelCell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
*
* @author alex
*/
public class BirdGui extends javax.swing.JFrame {
/**
* Creates new form BirdGui
*/
public void setAggiungi (String str){
String dato = str;
jTextArea1.append(dato);
}
public BirdGui() {
initComponents();
}
/**
* This method is called from within the constructor 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() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Leggi");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(20, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(24, Short.MAX_VALUE)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE))
);
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()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(25, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BirdGui leggi = new ThunderBirdGui();
leggi.getValori();
// System.out.println(dato);
// jTextArea1.append(dato);
}
public void getValori(){
Cell nome, cognome, nascita, anni, peso;
String nomeC = "";
String cognomeC = "";
String nascitaC = null;
int anniC = 0;
Double pesoC = 0.0;//in kg
LabelCell lc;
LabelCell dc;
NumberCell nc;
try {
//Apro il file di excel da leggere
Workbook workbook = Workbook.getWorkbook(new File("/home/alex/Scrivania/utenti.xls"));
//Seleziono il foglio sul quale voglio operare (il primo foglio ha indice 0)
Sheet sheet = workbook.getSheet(0);
//Leggo tutte le righe
int riga = 1;//indice riga, parto da 1 per saltare l'intestazione dei campi
int numeroRighe = sheet.getRows();//calcolo quante righe ci sono nel foglio
//Attento che c'è una riga in più per l'intestazione!
for(int i = 1; i < numeroRighe; i++){
//System.out.println(i);
nome = sheet.getCell(0, riga);
lc = (LabelCell)nome;
nomeC = lc.getString();
cognome = sheet.getCell(1, riga);
lc = (LabelCell)cognome;
cognomeC = lc.getString();
nascita = sheet.getCell(2, riga);
dc = (LabelCell)nascita;
nascitaC = dc.getString();
anni = sheet.getCell(3, riga);
nc = (NumberCell)anni;
anniC = (int)nc.getValue();
peso = sheet.getCell(4, riga);
nc = (NumberCell)peso;
pesoC = nc.getValue();
String valore = ("Riga: " + riga + " nome: " + nomeC + " Cognome: " + cognomeC + " Nascita: " + nascitaC + " età: " + anniC + " Peso: " + pesoC);
setAggiungi(valore);
//passo alla riga successiva
riga++;
}
//Chiudo excel e libero la memoria
workbook.close();
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* 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/tu...feel/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(BirdGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(BirdGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(BirdGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(BirdGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
BirdGui leggi = new BirdGui();
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new BirdGui().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}
// TODO Auto-generated method stub