/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lebaran; import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import java.sql.ResultSet; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableModel; /** * * @author Parul */ public class Tunjangan extends javax.swing.JFrame { Connection con; Statement stat; ResultSet res; String nip1, golongan1,status1; int gaji1; double thr1; /** * Creates new form Tunjangan */ public Tunjangan() { initComponents(); tampilkan_data(); } public void mouseClicked(java.awt.event.MouseEvent evt) { tabel_operatorMouseClicked(evt); } }); jScrollPane1.setViewportView(tabel_operator); jLabel1.setText("NIP"); jLabel2.setText("Status"); simpan.setText("Simpan"); simpan.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { simpanActionPerformed(evt); } }); jLabel3.setText("Golongan"); ubah.setText("Ubah"); ubah.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ubahActionPerformed(evt); }
}); jLabel4.setText("Gaji"); hapus.setText("Hapus"); hapus.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { hapusActionPerformed(evt); } }); jLabel5.setText("THR"); batal.setText("Batal"); batal.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { batalActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(jLabel2) .addComponent(jLabel4) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel5) .addGap(27, 27, 27))) .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(golongan, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nip, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(thr, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 23, Short.MAX_VALUE)) .addComponent(gaji)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(simpan) .addGap(35, 35, 35)
.addComponent(ubah) .addGap(41, 41, 41) .addComponent(hapus) .addGap(40, 40, 40) .addComponent(batal)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(simpan) .addComponent(ubah) .addComponent(hapus) .addComponent(batal))) .addGroup(layout.createSequentialGroup() .addGap(52, 52, 52) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(nip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(golongan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(gaji, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5) .addComponent(thr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(86, Short.MAX_VALUE)) ); pack(); }// private void koneksi(){ try{ Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost/lebaran","root",""); stat = con.createStatement(); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void simpan_data(){ koneksi(); try{ stat.executeUpdate("INSERT INTO tunjangan values(" + "'" + nip.getSelectedItem() + "'," + "'" + golongan.getSelectedItem() + "'," + "'" + status.getText()+ "'," + "'" + gaji.getText()+ "'," + "'" + thr.getText()+"')"); stat.close(); reset(); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void ubah_data(){ koneksi(); try{ stat.executeUpdate("UPDATE tunjangan SET " + + + + + +
"jenis_paket ='"+ golongan.getSelectedItem()+"'," "harga ='" + status.getText()+ "'," "masa_berlaku ='" + gaji.getText()+ "'," "bonus_kuota ='"+ thr.getText()+"'" "Where" "operator ='"+ nip.getSelectedItem()+"'");
stat.close(); reset(); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void hapus_data(){ koneksi(); try{ stat.executeUpdate("DELETE FROM tunjangan WHERE nip ='"+
nip.getSelectedItem()+"'"); stat.close(); reset(); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void tampilkan_data(){ DefaultTableModel dtm = new DefaultTableModel(); dtm.addColumn("NIP"); dtm.addColumn("Status"); dtm.addColumn("Golongan"); dtm.addColumn("Gaji"); dtm.addColumn("THR"); try{ koneksi(); ResultSet res = stat.executeQuery("select * from tunjangan"); while(res.next()){ dtm.addRow(new Object[]{ res.getString(1), res.getString(2), res.getString(3), res.getString(4), res.getString(5) }); } tabel_operator.setModel(dtm); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void reset(){ try{
}
nip.setSelectedItem(""); golongan.setSelectedItem(""); status.setText(""); gaji.setText(""); thr.setText(""); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); }
private void gajiActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void nipActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: nip1 = (String) nip.getSelectedItem(); if (nip1 == "--Pilih--"){ golongan.setSelectedItem(""); gaji.setText("");
thr.setText(""); golongan.setEnabled(false); gaji.setEnabled(false); thr.setEnabled(false); nip.requestFocus(); } else{ golongan.setEnabled(true); gaji.setEnabled(true); thr.setEnabled(true); if (nip1 == "P001"){ status1 = "PNS"; } else if (nip1 == "P002"){ status1 = "PNS"; } else if (nip1== "B002"){ status1 = "Bantu"; } else if (nip1 == "B001"){ status1 = "Bantu"; } else if (nip1== "K001"){ status1 = "Kontrak"; } else if (nip1 == "K002"){ status1 = "Kontrak"; } else if (nip1== "KM01"){ status1 = "Komite"; } else if (nip1 == "KM02"){ status1 = "Komite"; } status.setText(status1); }
}
private void golonganActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: golongan1 = (String) golongan.getSelectedItem(); if (status1 == "PNS" && golongan1 == "I"){ gaji1 = 3000000; thr1 = 0.2; } else if (status1 == "Komite" && golongan1 == "I"){ gaji1= 3000000; thr1 = 0.2; } else if (status1 == "Komite" && golongan1 == "II"){ gaji1= 3000000; thr1 = 0.2;
} else if (status1 == "Komite" && golongan1 == "III"){ gaji1= 3000000; thr1 = 0.2; } else if (status1 == "Komite" && golongan1 == "IV"){ gaji1= 0; thr1 = 0.2; } else if (status1 == "PNS" && golongan1 == "II"){ gaji1 = 3000000; thr1 = 0.2; } else if (status1 == "PNS" && golongan1 == "III"){ gaji1 = 3000000; thr1 = 0.2; } else if (status1 == "PNS" && golongan1 == "IV"){ gaji1 = 0; thr1 = 0.2; } else if (status1 == "Komite" && golongan1 == "IV"){ gaji1 = 2500000; thr1 = 0.2; } else if (status1 == "PNS" && golongan1 == "IV"){ gaji1 = 2500000; thr1 = 0.2; } else if (status1 == "Bantu" && golongan1 == "Tidak Ada"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Bantu" && golongan1 == "I"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Bantu" && golongan1 == "II"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Bantu" && golongan1 == "III"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Bantu" && golongan1 == "IV"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Kontrak" && golongan1 == "Tidak Ada"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Kontrak" && golongan1 == "I"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Kontrak" && golongan1 == "II"){
gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Kontrak" && golongan1 == "III"){ gaji1 = 1500000; thr1 = 0.2; } else if (status1 == "Kontrak" && golongan1 == "IV"){ gaji1 = 1500000; thr1 = 0.2; } thr1 = thr1 * gaji1; gaji.setText(Integer.toString(gaji1)); thr.setText(Double.toString(thr1)); } private void tabel_operatorMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: try{ int row = tabel_operator.getSelectedRow(); nip.setSelectedItem(tabel_operator.getValueAt(row, 0).toString()); golongan.setSelectedItem(tabel_operator.getValueAt(row, 1).toString()); status.setText(tabel_operator.getValueAt(row, 2).toString()); gaji.setText(tabel_operator.getValueAt(row, 3).toString()); thr.setText(tabel_operator.getValueAt(row, 4).toString()); }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } private void simpanActionPerformed(java.awt.event.ActionEvent evt) {
}
// TODO add your handling code here: simpan_data(); //Menginputkan Data tampilkan_data(); //Menampilkan Data reset(); //Mengosongkan Form
private void ubahActionPerformed(java.awt.event.ActionEvent evt) {
}
// TODO add your handling code here: ubah_data(); //Mengubah Data tampilkan_data(); //Menampilkan Data reset(); //Mengosongkan Form
private void hapusActionPerformed(java.awt.event.ActionEvent evt) {
}
// TODO add your handling code here: hapus_data(); //Menghapus Data tampilkan_data(); //Menampilkan Data reset(); //Mengosongkan Form
private void batalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: reset(); //Mengosongkan Form } private void thrActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } /** * @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 code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Tunjangan.class.getName()).log(java.util.logging .Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Tunjangan.class.getName()).log(java.util.logging .Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Tunjangan.class.getName()).log(java.util.logging .Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Tunjangan.class.getName()).log(java.util.logging .Level.SEVERE, null, ex); } //
}
/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Tunjangan().setVisible(true); } });
// Variables declaration - do not modify private javax.swing.JButton batal;
private javax.swing.JTextField gaji; private javax.swing.JComboBox<String> golongan; private javax.swing.JButton hapus; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JComboBox<String> nip; private javax.swing.JButton simpan; private javax.swing.JTextField status; private javax.swing.JTable tabel_operator; private javax.swing.JTextField thr; private javax.swing.JButton ubah; // End of variables declaration }