buku
/*
* 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 nmMaster;
import Class.classkoneksi;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
/**
*
* @author RPL
*/
public class Buku extends javax.swing.JFrame {
private String judulBuku;
private String isbnBuku;
private String penulisBuku;
private String penerbitBuku;
private String tahunBuku;
private String stokBuku;
private String pokokBuku;
private String jualBuku;
private String ppnBuku;
private String diskonBuku;
private boolean update = false;
/**
* Creates new form Buku
*/
public Buku() {
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);
initComponents();
this.setLocationRelativeTo(this);
}
private void pushData(){
tJudul.setText(this.getJudulBuku());
tIsbn.setText(this.getIsbnBuku());
tPenulis.setText(this.getPenulisBuku());
tPenerbit.setText(this.getPenerbitBuku());
tTahun.setText(this.getTahunBuku());
tStok.setText(this.getStokBuku());
tPokok.setText(this.getPokokBuku());
tJual.setText(this.getJualBuku());
tPpn.setText(this.getPpnBuku());
tDiskon.setText(this.getDiskonBuku());
}
public void bersih(){
tJudul.setText("");
tIsbn.setText("");
tPenulis.setText("");
tPenerbit.setText("");
tTahun.setText("");
tStok.setText("");
tPokok.setText("");
tJual.setText("");
tPpn.setText("");
tDiskon.setText("");
}
private void updateData() {
String judul = tJudul.getText();
String isbn = tIsbn.getText();
String penulis = tPenulis.getText();
String penerbit = tPenerbit.getText();
String tahun = tTahun.getText();
String stok = tStok.getText();
String pokok = tPokok.getText();
String jual = tJual.getText();
String ppn = tPpn.getText();
String diskon = tDiskon.getText();
String SQL = "UPDATE tbl_buku set judul = '"+judul+"',noisbn = '"+isbn+"',penulis = '"+penulis+"',penerbit = '"+penerbit+"',tahun = '"+tahun+"',stok = '"+stok+"',harga_pokok = '"+pokok+"',harga_jual = '"+jual+"',ppn = '"+ppn+"',diskon = '"+diskon+"' where judul='"+
this.getJudulBuku()+"'";
int status = classkoneksi.execute(SQL);
if(status>0){
JOptionPane.showMessageDialog(this, "data berhasil diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}else{
JOptionPane.showMessageDialog(this, "data gagal diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
private void simpan(){
if ("".equals(tJudul.getText()) || "".equals(tIsbn.getText()) || "".equals(tPenulis.getText()) ||
"".equals(tPenerbit.getText()) || "".equals(tTahun.getText()) || "".equals(tStok.getText())
|| "".equals(tPokok.getText()) || "".equals(tJual.getText()) || "".equals(tPpn.getText())
|| "".equals(tDiskon.getText())) {
JOptionPane.showMessageDialog(this, "Harap Lengkapi Data", "Eror", JOptionPane.WARNING_MESSAGE);
} else {
String SQL = "INSERT INTO tbl_buku (judul,noisbn,penulis,penerbit, tahun, stok, harga_pokok, harga_jual, ppn, diskon)"
+ "VALUES('"+tJudul.getText()+"','"+tIsbn.getText()+"','"+tPenulis.getText()+"','"+tPenerbit.getText()+"','"+tTahun.getText()+"'"
+ ",'"+tStok.getText()+"','"+tPokok.getText()+"','"+tJual.getText()+"','"+tPpn.getText()+"','"+tDiskon.getText()+"')";
int status = classkoneksi.execute(SQL);
if(status == 1) {
JOptionPane.showMessageDialog(this, "data berhasil ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
} else {
JOptionPane.showMessageDialog(this, "data gagal ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
}
/**
* 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">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
tJudul = new javax.swing.JTextField();
tIsbn = new javax.swing.JTextField();
tPenulis = new javax.swing.JTextField();
tPenerbit = new javax.swing.JTextField();
tTahun = new javax.swing.JTextField();
tJual = new javax.swing.JTextField();
tPokok = new javax.swing.JTextField();
tStok = new javax.swing.JTextField();
tPpn = new javax.swing.JTextField();
tDiskon = new javax.swing.JTextField();
btnSimpan = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 102)), "BUKU"));
jLabel2.setText("Judul");
jLabel3.setText("NoISBN");
jLabel4.setText("Penulis");
jLabel5.setText("Penerbit");
jLabel6.setText("Tahun");
jLabel7.setText("Stok");
jLabel8.setText("Harga Pokok");
jLabel9.setText("Harga Jual");
jLabel10.setText("PPN");
jLabel11.setText("Diskon");
btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900179_floppy_disk_save.png"))); // NOI18N
btnSimpan.setText("SIMPAN");
btnSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSimpanActionPerformed(evt);
}
});
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900274_ic_cancel_48px.png"))); // NOI18N
jButton2.setText("BATAL");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
jButton3.setText("KELUAR");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(jLabel2)
.addGap(29, 29, 29)
.addComponent(tJudul, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tTahun)
.addComponent(tPenerbit, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tPenulis)
.addComponent(tIsbn, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(49, 49, 49))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel8)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tStok)
.addComponent(tPokok)
.addComponent(tJual)
.addComponent(tPpn)
.addComponent(tDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tJudul, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tIsbn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tPenulis, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tPenerbit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tTahun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tStok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tPokok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tJual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tPpn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(tDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSimpan)
.addComponent(jButton2)
.addComponent(jButton3))))
.addContainerGap(35, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bersih();
}
private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(btnSimpan.getText().equals("Ubah")){
updateData();
}else{
simpan();
}
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
if(this.isUpdate()==true){
pushData();
btnSimpan.setText("Ubah");
}else{
btnSimpan.setText("Simpan");
}
}
/**
* @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(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Buku().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnSimpan;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField tDiskon;
private javax.swing.JTextField tIsbn;
private javax.swing.JTextField tJual;
private javax.swing.JTextField tJudul;
private javax.swing.JTextField tPenerbit;
private javax.swing.JTextField tPenulis;
private javax.swing.JTextField tPokok;
private javax.swing.JTextField tPpn;
private javax.swing.JTextField tStok;
private javax.swing.JTextField tTahun;
// End of variables declaration
/**
* @return the isbnBuku
*/
public String getIsbnBuku() {
return isbnBuku;
}
/**
* @param isbnBuku the isbnBuku to set
*/
public void setIsbnBuku(String isbnBuku) {
this.isbnBuku = isbnBuku;
}
/**
* @return the penulisBuku
*/
public String getPenulisBuku() {
return penulisBuku;
}
/**
* @param penulisBuku the penulisBuku to set
*/
public void setPenulisBuku(String penulisBuku) {
this.penulisBuku = penulisBuku;
}
/**
* @return the penerbitBuku
*/
public String getPenerbitBuku() {
return penerbitBuku;
}
/**
* @param penerbitBuku the penerbitBuku to set
*/
public void setPenerbitBuku(String penerbitBuku) {
this.penerbitBuku = penerbitBuku;
}
/**
* @return the tahunBuku
*/
public String getTahunBuku() {
return tahunBuku;
}
/**
* @param tahunBuku the tahunBuku to set
*/
public void setTahunBuku(String tahunBuku) {
this.tahunBuku = tahunBuku;
}
/**
* @return the stokBuku
*/
public String getStokBuku() {
return stokBuku;
}
/**
* @param stokBuku the stokBuku to set
*/
public void setStokBuku(String stokBuku) {
this.stokBuku = stokBuku;
}
/**
* @return the pokokBuku
*/
public String getPokokBuku() {
return pokokBuku;
}
/**
* @param pokokBuku the pokokBuku to set
*/
public void setPokokBuku(String pokokBuku) {
this.pokokBuku = pokokBuku;
}
/**
* @return the jualBuku
*/
public String getJualBuku() {
return jualBuku;
}
/**
* @param jualBuku the jualBuku to set
*/
public void setJualBuku(String jualBuku) {
this.jualBuku = jualBuku;
}
/**
* @return the ppnBuku
*/
public String getPpnBuku() {
return ppnBuku;
}
/**
* @param ppnBuku the ppnBuku to set
*/
public void setPpnBuku(String ppnBuku) {
this.ppnBuku = ppnBuku;
}
/**
* @return the diskonBuku
*/
public String getDiskonBuku() {
return diskonBuku;
}
/**
* @param diskonBuku the diskonBuku to set
*/
public void setDiskonBuku(String diskonBuku) {
this.diskonBuku = diskonBuku;
}
/**
* @return the update
*/
public boolean isUpdate() {
return update;
}
/**
* @param update the update to set
*/
public void setUpdate(boolean update) {
this.update = update;
}
/**
* @return the judulBuku
*/
public String getJudulBuku() {
return judulBuku;
}
/**
* @param judulBuku the judulBuku to set
*/
public void setJudulBuku(String judulBuku) {
this.judulBuku = judulBuku;
}
}
* 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 nmMaster;
import Class.classkoneksi;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
/**
*
* @author RPL
*/
public class Buku extends javax.swing.JFrame {
private String judulBuku;
private String isbnBuku;
private String penulisBuku;
private String penerbitBuku;
private String tahunBuku;
private String stokBuku;
private String pokokBuku;
private String jualBuku;
private String ppnBuku;
private String diskonBuku;
private boolean update = false;
/**
* Creates new form Buku
*/
public Buku() {
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);
initComponents();
this.setLocationRelativeTo(this);
}
private void pushData(){
tJudul.setText(this.getJudulBuku());
tIsbn.setText(this.getIsbnBuku());
tPenulis.setText(this.getPenulisBuku());
tPenerbit.setText(this.getPenerbitBuku());
tTahun.setText(this.getTahunBuku());
tStok.setText(this.getStokBuku());
tPokok.setText(this.getPokokBuku());
tJual.setText(this.getJualBuku());
tPpn.setText(this.getPpnBuku());
tDiskon.setText(this.getDiskonBuku());
}
public void bersih(){
tJudul.setText("");
tIsbn.setText("");
tPenulis.setText("");
tPenerbit.setText("");
tTahun.setText("");
tStok.setText("");
tPokok.setText("");
tJual.setText("");
tPpn.setText("");
tDiskon.setText("");
}
private void updateData() {
String judul = tJudul.getText();
String isbn = tIsbn.getText();
String penulis = tPenulis.getText();
String penerbit = tPenerbit.getText();
String tahun = tTahun.getText();
String stok = tStok.getText();
String pokok = tPokok.getText();
String jual = tJual.getText();
String ppn = tPpn.getText();
String diskon = tDiskon.getText();
String SQL = "UPDATE tbl_buku set judul = '"+judul+"',noisbn = '"+isbn+"',penulis = '"+penulis+"',penerbit = '"+penerbit+"',tahun = '"+tahun+"',stok = '"+stok+"',harga_pokok = '"+pokok+"',harga_jual = '"+jual+"',ppn = '"+ppn+"',diskon = '"+diskon+"' where judul='"+
this.getJudulBuku()+"'";
int status = classkoneksi.execute(SQL);
if(status>0){
JOptionPane.showMessageDialog(this, "data berhasil diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}else{
JOptionPane.showMessageDialog(this, "data gagal diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
private void simpan(){
if ("".equals(tJudul.getText()) || "".equals(tIsbn.getText()) || "".equals(tPenulis.getText()) ||
"".equals(tPenerbit.getText()) || "".equals(tTahun.getText()) || "".equals(tStok.getText())
|| "".equals(tPokok.getText()) || "".equals(tJual.getText()) || "".equals(tPpn.getText())
|| "".equals(tDiskon.getText())) {
JOptionPane.showMessageDialog(this, "Harap Lengkapi Data", "Eror", JOptionPane.WARNING_MESSAGE);
} else {
String SQL = "INSERT INTO tbl_buku (judul,noisbn,penulis,penerbit, tahun, stok, harga_pokok, harga_jual, ppn, diskon)"
+ "VALUES('"+tJudul.getText()+"','"+tIsbn.getText()+"','"+tPenulis.getText()+"','"+tPenerbit.getText()+"','"+tTahun.getText()+"'"
+ ",'"+tStok.getText()+"','"+tPokok.getText()+"','"+tJual.getText()+"','"+tPpn.getText()+"','"+tDiskon.getText()+"')";
int status = classkoneksi.execute(SQL);
if(status == 1) {
JOptionPane.showMessageDialog(this, "data berhasil ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
} else {
JOptionPane.showMessageDialog(this, "data gagal ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
}
/**
* 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">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
tJudul = new javax.swing.JTextField();
tIsbn = new javax.swing.JTextField();
tPenulis = new javax.swing.JTextField();
tPenerbit = new javax.swing.JTextField();
tTahun = new javax.swing.JTextField();
tJual = new javax.swing.JTextField();
tPokok = new javax.swing.JTextField();
tStok = new javax.swing.JTextField();
tPpn = new javax.swing.JTextField();
tDiskon = new javax.swing.JTextField();
btnSimpan = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 102)), "BUKU"));
jLabel2.setText("Judul");
jLabel3.setText("NoISBN");
jLabel4.setText("Penulis");
jLabel5.setText("Penerbit");
jLabel6.setText("Tahun");
jLabel7.setText("Stok");
jLabel8.setText("Harga Pokok");
jLabel9.setText("Harga Jual");
jLabel10.setText("PPN");
jLabel11.setText("Diskon");
btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900179_floppy_disk_save.png"))); // NOI18N
btnSimpan.setText("SIMPAN");
btnSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSimpanActionPerformed(evt);
}
});
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900274_ic_cancel_48px.png"))); // NOI18N
jButton2.setText("BATAL");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
jButton3.setText("KELUAR");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(jLabel2)
.addGap(29, 29, 29)
.addComponent(tJudul, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tTahun)
.addComponent(tPenerbit, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tPenulis)
.addComponent(tIsbn, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(49, 49, 49))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel8)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tStok)
.addComponent(tPokok)
.addComponent(tJual)
.addComponent(tPpn)
.addComponent(tDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tJudul, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tIsbn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tPenulis, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tPenerbit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tTahun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tStok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tPokok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tJual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tPpn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(tDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSimpan)
.addComponent(jButton2)
.addComponent(jButton3))))
.addContainerGap(35, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bersih();
}
private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(btnSimpan.getText().equals("Ubah")){
updateData();
}else{
simpan();
}
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
if(this.isUpdate()==true){
pushData();
btnSimpan.setText("Ubah");
}else{
btnSimpan.setText("Simpan");
}
}
/**
* @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(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Buku().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnSimpan;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField tDiskon;
private javax.swing.JTextField tIsbn;
private javax.swing.JTextField tJual;
private javax.swing.JTextField tJudul;
private javax.swing.JTextField tPenerbit;
private javax.swing.JTextField tPenulis;
private javax.swing.JTextField tPokok;
private javax.swing.JTextField tPpn;
private javax.swing.JTextField tStok;
private javax.swing.JTextField tTahun;
// End of variables declaration
/**
* @return the isbnBuku
*/
public String getIsbnBuku() {
return isbnBuku;
}
/**
* @param isbnBuku the isbnBuku to set
*/
public void setIsbnBuku(String isbnBuku) {
this.isbnBuku = isbnBuku;
}
/**
* @return the penulisBuku
*/
public String getPenulisBuku() {
return penulisBuku;
}
/**
* @param penulisBuku the penulisBuku to set
*/
public void setPenulisBuku(String penulisBuku) {
this.penulisBuku = penulisBuku;
}
/**
* @return the penerbitBuku
*/
public String getPenerbitBuku() {
return penerbitBuku;
}
/**
* @param penerbitBuku the penerbitBuku to set
*/
public void setPenerbitBuku(String penerbitBuku) {
this.penerbitBuku = penerbitBuku;
}
/**
* @return the tahunBuku
*/
public String getTahunBuku() {
return tahunBuku;
}
/**
* @param tahunBuku the tahunBuku to set
*/
public void setTahunBuku(String tahunBuku) {
this.tahunBuku = tahunBuku;
}
/**
* @return the stokBuku
*/
public String getStokBuku() {
return stokBuku;
}
/**
* @param stokBuku the stokBuku to set
*/
public void setStokBuku(String stokBuku) {
this.stokBuku = stokBuku;
}
/**
* @return the pokokBuku
*/
public String getPokokBuku() {
return pokokBuku;
}
/**
* @param pokokBuku the pokokBuku to set
*/
public void setPokokBuku(String pokokBuku) {
this.pokokBuku = pokokBuku;
}
/**
* @return the jualBuku
*/
public String getJualBuku() {
return jualBuku;
}
/**
* @param jualBuku the jualBuku to set
*/
public void setJualBuku(String jualBuku) {
this.jualBuku = jualBuku;
}
/**
* @return the ppnBuku
*/
public String getPpnBuku() {
return ppnBuku;
}
/**
* @param ppnBuku the ppnBuku to set
*/
public void setPpnBuku(String ppnBuku) {
this.ppnBuku = ppnBuku;
}
/**
* @return the diskonBuku
*/
public String getDiskonBuku() {
return diskonBuku;
}
/**
* @param diskonBuku the diskonBuku to set
*/
public void setDiskonBuku(String diskonBuku) {
this.diskonBuku = diskonBuku;
}
/**
* @return the update
*/
public boolean isUpdate() {
return update;
}
/**
* @param update the update to set
*/
public void setUpdate(boolean update) {
this.update = update;
}
/**
* @return the judulBuku
*/
public String getJudulBuku() {
return judulBuku;
}
/**
* @param judulBuku the judulBuku to set
*/
public void setJudulBuku(String judulBuku) {
this.judulBuku = judulBuku;
}
}
Comments
Post a Comment