public void tableChanged(TableModelEvent e) { int baris = e.getFirstRow(); int kolom = e.getColumn(); System.out.print("Terjadi perubahan di "); System.out.print("baris " + baris); System.out.println("kolom " + kolom); TableModel model = (TableModel) e.getSource(); Object data = model.getValueAt(baris, kolom); System.out.println("Data baru : " + data); }
public void tableChanged(TableModelEvent tme) { int baris = tme.getFirstRow(); int kolom = tme.getColumn(); TableModel model = (TableModel) tme.getSource(); int id = (Integer) model.getValueAt(baris, 0); String query = ""; switch (kolom) { case 1: String nama = (String) model.getValueAt(baris, kolom); query = "UPDATE produk SET nama_produk='" + nama + "' WHERE id_produk=" + id; prosesEdit(query); break; case 2: String jenis = (String) model.getValueAt(baris, kolom); try { query = "select * from jenis where nama_jenis='" + jenis + "'"; ResultSet rs = stm.executeQuery(query); if (rs.next()) { int idJenis = rs.getInt("id_jenis"); query = "UPDATE produk SET id_jenis=" + idJenis + " WHERE id_produk=" + id; prosesEdit(query); } else { setDataTabel(); JOptionPane.showMessageDialog(null, "gagal,jenis tidak ada"); } } catch (SQLException SQLerr) { SQLerr.printStackTrace(); } break; case 3: int stok = (Integer) model.getValueAt(baris, kolom); query = "UPDATE `stok_produk` SET stok=" + stok + " WHERE id_produk=" + id; prosesEdit(query); break; case 4: int harga = (Integer) model.getValueAt(baris, kolom); query = "UPDATE produk SET harga=" + harga + " WHERE id_produk=" + id; prosesEdit(query); break; case 5: String suplier = (String) model.getValueAt(baris, kolom); try { query = "SELECT * FROM suplier WHERE nama_suplier='" + suplier + "'"; ResultSet rs = stm.executeQuery(query); if (rs.next()) { int idSuplier = rs.getInt("id_suplier"); query = "UPDATE produk SET id_suplier=" + idSuplier + " WHERE id_produk=" + id; prosesEdit(query); } else { setDataTabel(); JOptionPane.showMessageDialog(null, "gagal,suplier belum terdaftar"); } } catch (SQLException SQLerr) { SQLerr.printStackTrace(); } break; default: break; } }
public void tableChanged(TableModelEvent e) { if (e.getSource() == this.encryptionConfigurationTableModel) { loadStates(); } }