Salve ragazzi,
sono alle prese con la creazione di un form in cui devo inserire una data, memorizzarla e passarla, tramite il comando ESEGUI, ad una classe.
ecco il codice di quello che ho fatto:
codice:package gui; // in questo package sono presenti anche Netto.java e Lavorazione.java import correggi_flag.*; // il mio package dove è presente il file ProvaSFM.java import java.util.Date; import java.text.DateFormat; /** * * @author cFigura */ public class Pannello extends javax.swing.JFrame { /** * Creates new form Pannello */ public Pannello() { 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() { Desktop = new javax.swing.JDesktopPane(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem3 = new javax.swing.JMenuItem(); jMenuItem4 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); Desktop.setBackground(new java.awt.Color(51, 153, 255)); Desktop.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N jLabel1.setText("Inserisci la data "); jLabel1.setName(""); // NOI18N jLabel1.setBounds(30, 30, 120, 30); Desktop.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); jTextField1.setBounds(150, 30, 180, 30); Desktop.add(jTextField1, javax.swing.JLayeredPane.DEFAULT_LAYER); jButton1.setText("Esegui!"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton1.setBounds(150, 120, 100, 30); Desktop.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER); jMenu1.setText("File"); jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK)); jMenuItem1.setText("Termina"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuBar1.add(jMenu1); jMenu2.setText("Visualizza"); jMenuItem3.setText("Tempo lavorazione"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu2.add(jMenuItem3); jMenuItem4.setText("Tempo netto"); jMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem4ActionPerformed(evt); } }); jMenu2.add(jMenuItem4); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Desktop, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Desktop, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Lavorazione l = new Lavorazione(); Desktop.add(l); l.setVisible(true); } private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Netto n = new Netto(); Desktop.add(n); n.setVisible(true); } private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: new ProvaSFM(); } /** * @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(Pannello.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Pannello.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Pannello.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Pannello.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Pannello().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JDesktopPane Desktop; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JTextField jTextField1; // End of variables declaration }
la mia domanda è:
Come faccio ad impostare il textfield come datatime? E poi come memorizzo quello che scrivo nel textfield per passarlo a Prova SFM quando si clicca sul Jbutton?
Grazie

Rispondi quotando