I'm doing a Swing app in Java with a database. I got different JButton
which delete, add or modified row in a JTable
.
I'm stuck because I don't know where I can manage my action listener.
I have a class named DaoClef
where I will execute an SQL statement, send my table model etc...
I got a view where all my button are set but I don't know what to do in my controller.
For now I got this in the view:
btnNew.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// check for selected row first
if (t.getSelectedRow() != -1) {
// remove selected row from the model
String sqlMaj = "DELETE FROM clefs WHERE IdClef = ?";
try (PreparedStatement pst = Connect.getConnection().prepareStatement(sqlMaj) )
{
pst.setInt(1, (int) t.getValueAt(t.getSelectedRow(), 0));
pst.executeUpdate();
t.addNotify();
}
catch (SQLException e)
{
}
}
}
});
But it's not good because the SQL statement need to be execute in a method in the controller.
Can you give me some clues?