/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">
// TODO add your handling code here: try{ if (kd_brg.getText().isEmpty()){ JOptionPane.showMessageDialog(null, " Kode Barang Belum diIsi !! ", "Warning Message",JOptionPane.WARNING_MESSAGE); }else if (add==true){ stm.executeUpdate("INSERT INTO barang VALUES('"+kd_brg.getText() +"','"+nm_brg.getText()+"','"+jTextField1.getText()+"','"+jharga.getText()+"','" +jstok.getText()+"','"+sm.getText()+"')" ); baca_data(); JOptionPane.showMessageDialog(null, " Data Berhasil Disimpan !! ", "Warning Message",JOptionPane.WARNING_MESSAGE); bersih(); }else if (edit==true){ stm.executeUpdate("UPDATE barang set nama_barang='"+nm_brg.getTe xt()+"',satuan='"+jTextField1.getText()+"',harga='"+jharga.getText()+"',stok='"+ jstok.getText()+"',stok_minimal='"+sm.getText()+"' WHERE kode_barang='"+kd_brg.g etText()+"'"); baca_data(); JOptionPane.showMessageDialog(null, " Data Berhasil Diupdate !! ", "Warning Message",JOptionPane.WARNING_MESSAGE); bersih(); } jTable1.setModel(new DefaultTableModel(dataTable,header)); baca_data(); }catch(Exception e){
// TODO add your handling code here: edit=true; disable_Text(true); disable_button(false); if (edit==true){ add=false; edit=true; } bersih(); jsave.setText("Update"); } private void jdeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: try{ stm.executeUpdate("DELETE FROM barang where kode_barang='"+kd_brg.ge tText()+"'"); baca_data(); JOptionPane.showMessageDialog(null, " Data Behasil Dihapus !! ", "Wa rning Message",JOptionPane.WARNING_MESSAGE); bersih(); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void jexitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: dispose(); } private void jcancelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: disable_Text(false); disable_button(true); bersih(); jdelete.setEnabled(false); } private void stsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: if (sts.getSelectedItem().equals("Kg")){ jTextField1.setText("Kg"); }else if (sts.getSelectedItem().equals("Liter")){ jTextField1.setText("Liter"); }else if (sts.getSelectedItem().equals("KM")){ jTextField1.setText("KM"); }else if (sts.getSelectedItem().equals("Gram")){ jTextField1.setText("Gram"); }else if (sts.getSelectedItem().equals("Newton")){ jTextField1.setText("Newton"); }else if(sts.getSelectedItem().equals("Ton")){ jTextField1.setText("Ton"); }else if (sts.getSelectedItem().equals("Kwintal")){ jTextField1.setText("Kwintal"); }else if (sts.getSelectedItem().equals("Abad")){ jTextField1.setText("Abad"); }else{ jTextField1.setText("Lainnya"); } } private void jprintActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: cetak_barang(); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod e (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the d efault look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lo okandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana ger.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(frmBarang.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(frmBarang.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(frmBarang.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(frmBarang.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmBarang().setVisible(true); } }); }