I have 2 checkbox Male and Female. I want when I click to Male checkbox and press button Add, the row of Table will get value "Male", I use addItemListener to checkbox but I have to press 2 times then the value appear. So can anyone know how to do that easier. Thank you !
public void Add () throws SQLException
{
String MNV = TX1.getText();
String HNV = TX2.getText();
String TNV = TX3.getText();
String GT1 = Nam.getText();
String GT2 = Nu.getText();
String NS = TX5.getText();
String TD = TX6.getText();
String SDT = TX7.getText();
String DC = TX8.getText();
Statement s = connect.createStatement();
Nam.addItemListener(new ItemListener()
{
public void itemStateChanged (ItemEvent E)
{
try {
s.execute("INSERT INTO `nhanvien` "
+ "(`MÃ NV`, `HỌ NV`, `TÊN NV`, `GIỚI TÍNH`, `NĂM SINH`, `TRÌNH ĐỘ`, `SỐ ĐT`, `ĐỊA CHỈ`)"
+ " VALUES ('"+MNV+"', '"+HNV+"', '"+TNV+"', '"+GT1+"', '"+NS+"', '"+TD+"', '"+SDT+"', '"+DC+"');");
GetData();
} catch (SQLException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
Aucun commentaire:
Enregistrer un commentaire