list 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 java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author RPL
*/
public class ListBuku extends javax.swing.JFrame {
/**
* Creates new form DaftarBuku
*/
public ListBuku() {
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);
initComponents();
this.setLocationRelativeTo(this);
selectData();
}
public void selectData(){
String kolom[] = {"judul","noisbn","penulis","penerbit","tahun","stok","harga_pokok","harga_jual","ppn","diskon"};
DefaultTableModel dtm = new DefaultTableModel(null, kolom);
String SQL = "SELECT judul, noisbn, penulis, penerbit, tahun, stok, harga_pokok, harga_jual, ppn, diskon FROM tbl_buku";
ResultSet rs = classkoneksi.executeQuery(SQL);
try{
while(rs.next()){
String judul = rs.getString(1);
String noisbn = rs.getString(2);
String penulis = rs.getString(3);
String penerbit = rs.getString(4);
String tahun = rs.getString(5);
String stok = rs.getString(6);
String harga_pokok = rs.getString(7);
String harga_jual = rs.getString(8);
String ppn = rs.getString(9);
String diskon = rs.getString(10);
String data[] = {judul,noisbn,penulis,penerbit,tahun,stok,harga_pokok,harga_jual,ppn,diskon};
dtm.addRow(data);
}
}catch(SQLException ex) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, ex);
}
tblData.setModel(dtm);
}
private void search() {
DefaultTableModel table = new DefaultTableModel();
table.addColumn("judul");
table.addColumn("noisbn");
table.addColumn("penulis");
table.addColumn("penerbit");
table.addColumn("tahun");
table.addColumn("stok");
table.addColumn("harga_pokok");
table.addColumn("harga_jual");
table.addColumn("ppn");
table.addColumn("diskon");
String keyword = txtCari.getText();
try{
String SQL = "SELECT judul, noisbn, penulis, penerbit, tahun, stok, harga_pokok, harga_jual, ppn, diskon FROM tbl_buku where judul like '%"+keyword+"%' or noisbn like '%"+keyword+"%' or penulis like '%"+keyword+"%' "
+ "or penerbit like '%"+keyword+"%' or tahun like '%"+keyword+"%' or stok like '%"+keyword+"%' or harga_pokok like '%"+keyword+"%' or harga_jual like '%"+keyword+"%' "
+ "or ppn like '%"+keyword+"%' or diskon like '%"+keyword+"%'";
ResultSet rs = classkoneksi.executeQuery(SQL);
while(rs.next()) {
table.addRow(new Object[] {
rs.getString("judul"),
rs.getString("noisbn"),
rs.getString("penulis"),
rs.getString("penerbit"),
rs.getString("tahun"),
rs.getString("stok"),
rs.getString("harga_pokok"),
rs.getString("harga_jual"),
rs.getString("ppn"),
rs.getString("diskon")
});
}
}catch(Exception e) {
System.out.println(e);
}
tblData.setModel(table);
}
/**
* 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();
jScrollPane1 = new javax.swing.JScrollPane();
tblData = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
txtCari = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 153)), "Daftar Buku"));
tblData.setAutoCreateRowSorter(true);
tblData.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(tblData);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900013_icons_add.png"))); // NOI18N
jButton1.setText("BARU");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900340_delete.png"))); // NOI18N
jButton3.setText("HAPUS");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900315_sync.png"))); // NOI18N
jButton4.setText("REFRESH");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
jButton5.setText("KELUAR");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/edit.png"))); // NOI18N
jButton6.setText("RUBAH");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
txtCari.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtCariActionPerformed(evt);
}
});
txtCari.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txtCariKeyReleased(evt);
}
});
jLabel1.setText("CARI");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 462, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton5))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtCari, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtCari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton6)
.addComponent(jButton5))
.addContainerGap())
);
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 jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Buku ds = new Buku();
ds.setVisible(true);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
selectData();
}
private void txtCariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txtCariKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
search();
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int baris = tblData.getSelectedRow();{
String judul = tblData.getValueAt(baris, 0).toString();
String isbn = tblData.getValueAt(baris, 1).toString();
String penulis = tblData.getValueAt(baris, 2).toString();
String penerbit = tblData.getValueAt(baris, 3).toString();
String tahun = tblData.getValueAt(baris, 4).toString();
String stok = tblData.getValueAt(baris, 5).toString();
String pokok = tblData.getValueAt(baris, 6).toString();
String jual = tblData.getValueAt(baris, 7).toString();
String ppn = tblData.getValueAt(baris, 8).toString();
String diskon = tblData.getValueAt(baris, 9).toString();
if(baris != -1) {
Buku dist = new Buku();
dist.setJudulBuku(judul);
dist.setIsbnBuku(isbn);
dist.setPenulisBuku(penulis);
dist.setPenerbitBuku(penerbit);
dist.setTahunBuku(tahun);
dist.setStokBuku(stok);
dist.setPokokBuku(pokok);
dist.setJualBuku(jual);
dist.setPpnBuku(ppn);
dist.setDiskonBuku(diskon);
dist.setUpdate(true);
dist.setVisible(true);
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(this, "pilih baris data terlebih dahulu", "eror", JOptionPane.WARNING_MESSAGE);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:int baris = tblData.getSelectedRow();
int baris = tblData.getSelectedRow();
if (baris != -1) {
String judul = tblData.getValueAt(baris, 0).toString();
String SQL = "DELETE FROM tbl_buku WHERE judul='"+judul+"'";
int status = classkoneksi.execute(SQL);
if (status==1) {
JOptionPane.showMessageDialog(this, "data berhasil di hapus", "sukse", JOptionPane.INFORMATION_MESSAGE );
selectData();
}else {
JOptionPane.showMessageDialog(this, "Data gagal dihapus", "Gagal", JOptionPane.WARNING_MESSAGE);
}
}else {
JOptionPane.showMessageDialog(this, "pilih baris data terlebih dahulu", "eror", JOptionPane.WARNING_MESSAGE);
}
}
/**
* @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(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ListBuku().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tblData;
private javax.swing.JTextField txtCari;
// End of variables declaration
}
* 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 java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author RPL
*/
public class ListBuku extends javax.swing.JFrame {
/**
* Creates new form DaftarBuku
*/
public ListBuku() {
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);
initComponents();
this.setLocationRelativeTo(this);
selectData();
}
public void selectData(){
String kolom[] = {"judul","noisbn","penulis","penerbit","tahun","stok","harga_pokok","harga_jual","ppn","diskon"};
DefaultTableModel dtm = new DefaultTableModel(null, kolom);
String SQL = "SELECT judul, noisbn, penulis, penerbit, tahun, stok, harga_pokok, harga_jual, ppn, diskon FROM tbl_buku";
ResultSet rs = classkoneksi.executeQuery(SQL);
try{
while(rs.next()){
String judul = rs.getString(1);
String noisbn = rs.getString(2);
String penulis = rs.getString(3);
String penerbit = rs.getString(4);
String tahun = rs.getString(5);
String stok = rs.getString(6);
String harga_pokok = rs.getString(7);
String harga_jual = rs.getString(8);
String ppn = rs.getString(9);
String diskon = rs.getString(10);
String data[] = {judul,noisbn,penulis,penerbit,tahun,stok,harga_pokok,harga_jual,ppn,diskon};
dtm.addRow(data);
}
}catch(SQLException ex) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, ex);
}
tblData.setModel(dtm);
}
private void search() {
DefaultTableModel table = new DefaultTableModel();
table.addColumn("judul");
table.addColumn("noisbn");
table.addColumn("penulis");
table.addColumn("penerbit");
table.addColumn("tahun");
table.addColumn("stok");
table.addColumn("harga_pokok");
table.addColumn("harga_jual");
table.addColumn("ppn");
table.addColumn("diskon");
String keyword = txtCari.getText();
try{
String SQL = "SELECT judul, noisbn, penulis, penerbit, tahun, stok, harga_pokok, harga_jual, ppn, diskon FROM tbl_buku where judul like '%"+keyword+"%' or noisbn like '%"+keyword+"%' or penulis like '%"+keyword+"%' "
+ "or penerbit like '%"+keyword+"%' or tahun like '%"+keyword+"%' or stok like '%"+keyword+"%' or harga_pokok like '%"+keyword+"%' or harga_jual like '%"+keyword+"%' "
+ "or ppn like '%"+keyword+"%' or diskon like '%"+keyword+"%'";
ResultSet rs = classkoneksi.executeQuery(SQL);
while(rs.next()) {
table.addRow(new Object[] {
rs.getString("judul"),
rs.getString("noisbn"),
rs.getString("penulis"),
rs.getString("penerbit"),
rs.getString("tahun"),
rs.getString("stok"),
rs.getString("harga_pokok"),
rs.getString("harga_jual"),
rs.getString("ppn"),
rs.getString("diskon")
});
}
}catch(Exception e) {
System.out.println(e);
}
tblData.setModel(table);
}
/**
* 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();
jScrollPane1 = new javax.swing.JScrollPane();
tblData = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
txtCari = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 153)), "Daftar Buku"));
tblData.setAutoCreateRowSorter(true);
tblData.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(tblData);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900013_icons_add.png"))); // NOI18N
jButton1.setText("BARU");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900340_delete.png"))); // NOI18N
jButton3.setText("HAPUS");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900315_sync.png"))); // NOI18N
jButton4.setText("REFRESH");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
jButton5.setText("KELUAR");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/edit.png"))); // NOI18N
jButton6.setText("RUBAH");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
txtCari.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtCariActionPerformed(evt);
}
});
txtCari.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txtCariKeyReleased(evt);
}
});
jLabel1.setText("CARI");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 462, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton5))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtCari, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtCari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton6)
.addComponent(jButton5))
.addContainerGap())
);
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 jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Buku ds = new Buku();
ds.setVisible(true);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
selectData();
}
private void txtCariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txtCariKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
search();
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int baris = tblData.getSelectedRow();{
String judul = tblData.getValueAt(baris, 0).toString();
String isbn = tblData.getValueAt(baris, 1).toString();
String penulis = tblData.getValueAt(baris, 2).toString();
String penerbit = tblData.getValueAt(baris, 3).toString();
String tahun = tblData.getValueAt(baris, 4).toString();
String stok = tblData.getValueAt(baris, 5).toString();
String pokok = tblData.getValueAt(baris, 6).toString();
String jual = tblData.getValueAt(baris, 7).toString();
String ppn = tblData.getValueAt(baris, 8).toString();
String diskon = tblData.getValueAt(baris, 9).toString();
if(baris != -1) {
Buku dist = new Buku();
dist.setJudulBuku(judul);
dist.setIsbnBuku(isbn);
dist.setPenulisBuku(penulis);
dist.setPenerbitBuku(penerbit);
dist.setTahunBuku(tahun);
dist.setStokBuku(stok);
dist.setPokokBuku(pokok);
dist.setJualBuku(jual);
dist.setPpnBuku(ppn);
dist.setDiskonBuku(diskon);
dist.setUpdate(true);
dist.setVisible(true);
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(this, "pilih baris data terlebih dahulu", "eror", JOptionPane.WARNING_MESSAGE);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:int baris = tblData.getSelectedRow();
int baris = tblData.getSelectedRow();
if (baris != -1) {
String judul = tblData.getValueAt(baris, 0).toString();
String SQL = "DELETE FROM tbl_buku WHERE judul='"+judul+"'";
int status = classkoneksi.execute(SQL);
if (status==1) {
JOptionPane.showMessageDialog(this, "data berhasil di hapus", "sukse", JOptionPane.INFORMATION_MESSAGE );
selectData();
}else {
JOptionPane.showMessageDialog(this, "Data gagal dihapus", "Gagal", JOptionPane.WARNING_MESSAGE);
}
}else {
JOptionPane.showMessageDialog(this, "pilih baris data terlebih dahulu", "eror", JOptionPane.WARNING_MESSAGE);
}
}
/**
* @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(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ListBuku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ListBuku().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tblData;
private javax.swing.JTextField txtCari;
// End of variables declaration
}
Comments
Post a Comment