alla fine penso di fare...
due pulsanti sfoglia che mi cercano uno il file di testo, e l'altro il file excel
e un pulsante elabora che mi farà il parsing dei due file è mi crea unaltro file excel stavolta asssociandomi l'ID al nome.
Ora sto iniziando ma la vedo molto dura...
con l'aiuto di netbeans
mi sono creato un frame ed ho messo due pulsanti sfoglia.
come questa:
ora al click di sfoglia vorrei far aprire loggetto filechooser
come faccio...?
chiedo l'impossibile..? vedo che con netbeans mi aiuta molto anche se sono inesperto...
ma... c'è tanto da studiare..
il codice è questo:
Codice PHP:
package javaapplication1;
import java.io.File;
import javax.swing.JFileChooser;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Sfoglia1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("Seleziona il file di testo ");
jLabel2.setText("Seleziona il file excel");
jButton2.setText("Sfoglia2");
jTextField1.setText("jTextField1");
jTextField2.setText("jTextField2");
jButton3.setText("Elabora e crea file excel");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(34, 34, 34)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2))
.add(26, 26, 26)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 388, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 391, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(15, 15, 15)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton2)
.add(jButton1)))
.add(layout.createSequentialGroup()
.add(242, 242, 242)
.add(jButton3)))
.addContainerGap(70, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(99, 99, 99)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.add(76, 76, 76)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jButton2)
.addContainerGap())
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 117, Short.MAX_VALUE)
.add(jButton3)
.add(64, 64, 64))))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String command = evt.getActionCommand();
if(command == "Sfoglia1") {
}
if(command == "Sfoglia2") {
}
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
CON questo dovrei controllare la pressione sul tasto sfoglia1 vero..?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String command = evt.getActionCommand();
if(command == "Sfoglia1") {
}
}
Ma come faccio a dire fammi visualizzare l'oggetto filechooser
grazie per l'aiuto e buona serata