예제 #1
0
 private void btnHapusActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnHapusActionPerformed
   try {
     if (selected != null) {
       // konfirmasi dan proses hapus
       if (JOptionPane.showConfirmDialog(
               this,
               "Hapus?",
               "Konfirmasi",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE)
           == JOptionPane.YES_OPTION) {
         kelurahanDAO.delete(selected);
         loadTable();
         JOptionPane.showMessageDialog(this, "Data terhapus");
         clearForm();
       }
       setEnableForm(false);
       clearForm();
       btnTambah.setEnabled(true);
       btnUbah.setEnabled(false);
       btnHapus.setEnabled(false);
       btnSimpan.setEnabled(false);
       btnBatal.setEnabled(false);
       selected = null;
     }
   } catch (Exception ex) {
     JOptionPane.showMessageDialog(this, ex.getMessage());
   }
 } // GEN-LAST:event_btnHapusActionPerformed
예제 #2
0
 private void btnSimpanActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSimpanActionPerformed
   try {
     if (cmbKecamatan.getSelectedItem() != null) {
       if (selected == null) { // insert
         // insert data
         Kelurahan kel = new Kelurahan();
         kel.setNama(txtNama.getText());
         kel.setKecamatan((Kecamatan) cmbKecamatan.getSelectedItem());
         kelurahanDAO.insert(kel);
         loadTable();
         JOptionPane.showMessageDialog(this, "Data tersimpan");
         setEnableForm(false);
         clearForm();
         btnSimpan.setEnabled(false);
         btnBatal.setEnabled(false);
         btnUbah.setEnabled(false);
         btnHapus.setEnabled(false);
         btnTambah.setEnabled(true);
       } else {
         // update data
         selected.setNama(txtNama.getText());
         selected.setKecamatan((Kecamatan) cmbKecamatan.getSelectedItem());
         kelurahanDAO.update(selected);
         loadTable();
         setEnableForm(false);
         btnTambah.setEnabled(false);
         btnUbah.setEnabled(true);
         btnHapus.setEnabled(true);
         btnSimpan.setEnabled(false);
         btnBatal.setEnabled(true);
         selected = null;
       }
     } else {
       JOptionPane.showMessageDialog(this, "Input data dengan lengkap");
     }
   } catch (Exception ex) {
     JOptionPane.showMessageDialog(this, ex.getMessage());
   }
 } // GEN-LAST:event_btnSimpanActionPerformed
예제 #3
0
 private void loadTable() {
   try {
     list = kelurahanDAO.gets();
     String title[] = {"Kecamatan", "Kelurahan"};
     Object data[][] = new Object[list.size()][2];
     int row = 0;
     for (Kelurahan kel : list) {
       data[row][0] = kel.getKecamatan().getNama();
       data[row][1] = kel.getNama();
       ++row;
     }
     DefaultTableModel model = new DefaultTableModel(data, title);
     tblKelurahan.setModel(model);
   } catch (Exception ex) {
     JOptionPane.showMessageDialog(this, ex.getMessage());
   }
 }