I've created a custom JtextField
but any proprety defined method don't working like getText or SetText when I call it in the main JFrame
.
import javax.swing.JTextField;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class JTextFieldDecimal extends JTextField {
private static final long serialVersionUID = 1L;
public JTextFieldDecimal()
{
super();
addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c =e.getKeyChar();
if(!((c>='0') && (c<='9') ||
(c==KeyEvent.VK_BACK_SPACE) ||
(c==KeyEvent.VK_DELETE)))
{
getToolkit().beep();
e.consume();
}
}
});
}
}
when I click in validation button in jframe Produit the compiler give me an error and point to line 98 wich content my statement parameter of Custom JtextField named txtPrixHT.
btnValider.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Connection cn=null;
PreparedStatement pst =null;
ResultSet rs=null;
try {
Class.forName("com.mysql.jdbc.Driver");
cn=DriverManager.getConnection("jdbc:mysql://localhost/gesticom", "root","");
//String sqlAdd ="insert into produit (PrCodeBarre,PrDesignation,PrPrixHT,PrRemise,PrPrixAchat,PrStockAlerte,PrStockReel) values (?,?,?,?,?,?,?)";
String sqlAdd ="insert into produit (PrCodeBarre,PrDesignation,PrPrixHT) values (?,?,?)";
pst=cn.prepareStatement(sqlAdd,Statement.RETURN_GENERATED_KEYS);
pst.setString(1, txtCodebarre.getText());
pst.setString(2, txtDesignation.getText());
pst.setString(3,txtPrixHT.getText());
pst.execute();
rs=pst.getGeneratedKeys();
if(rs.next())
{
txtIdprod.setText(rs.getString(1));
JOptionPane.showMessageDialog(null, "Nouveau Produit créé", "Fournisseur",JOptionPane.INFORMATION_MESSAGE);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try
{
cn.close();
pst.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
});