Olá;
Tenho um formulário de cadastro com Código, Nome e Telefone e um botão chamado Exibir mas quando entro com os dados nos TextFields e clico no botão Exibir, a saída dos dados está sendo Null. Vejam parte do código.
public class Fornec extends javax.swing.JFrame {
private String Codigo;
/** Creates new form Fornec */
public Fornec() {
initComponents();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
EdCodigo = new javax.swing.JTextField();
BExibir = new javax.swing.JButton();
EdCodigo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EdCodigoActionPerformed(evt);
}
});
jPanel1.add(EdCodigo);
EdCodigo.setBounds(10, 40, 240, 20);
});
BExibir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BExibirActionPerformed(evt);
}
});
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
setBounds(100, 120, 408, 288);
}
private void EdCodigoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Codigo = evt.getActionCommand();
}
private void BExibirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println(Codigo);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Fornec().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton BExibir;
private javax.swing.JTextField EdCodigo;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
Valeu.