of 39 /39
LAPORAN KELOMPOK 14 TOKO BUKU MURAH MERIAH MATA KULIAH PEMROGRAMAN JAVA STMIK EL RAHMA YOGYAKARTA PROGRAM STUDI TEKNIK INFORMATIKA TAHUN 2012

LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Embed Size (px)

Citation preview

Page 1: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

LAPORAN KELOMPOK 14

TOKO BUKU MURAH MERIAH

MATA KULIAH PEMROGRAMAN JAVA

STMIK EL RAHMA YOGYAKARTA

PROGRAM STUDI TEKNIK INFORMATIKA

TAHUN 2012

Page 2: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 2

KELOMPOK 14

1. Rian Agustianto 12100913

2. Rudi Susanto 12100917

3. Sutardi 12100930

Page 3: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 3

HALAMAN PEMBUKA

Alhamdulillah, puji syukur penyusun haturkan kehadirat Allah SWT. Atas rahmat-Nya

lah Penulis dapat menyelesaikan laporan ini tepat pada waktunya.Tak lupa penyusun juga

menghaturkan terima kasih yang sebesar-besarnya kepada semua pihak yang telah

mendukung dan membantu dalam menyelesaikan laporan ini.

Laporan ini membahas tentang studi kasus pada Toko Buku Murah Meriah dimana toko

buku tersebut mempunyai sejumlah buku yang belum terinventarisir dengan baik. Maka dari

itu, perlu dibuat sebuah sistem database yang akan menampung data buku tersebut. Sistem

ini tentu tidak bias berjalan sendirian. Diperlukan suatu interface yang user friendly sehingga

pengguna tidak mengalami kesulitan dalam menggunakan sistem tersebut. Interface itu

sendiri kami buat dengan aplikasi Java sesuai mata kuliah yang ditempuh yaitu

Pemrograman Java.

Namun demikian, penyusun merasa masih banyak sekali kekurangan dalam penyusunan

laporan maupun program ini, sesuai dengan pepatah yang mengatakan bahwa tak ada

gading yang tak retak. Oleh karena itu, segala saran dan kritik yang membangun dari yang

lebih berkompeten di bidang pemrograman Java, penyusun terima dengan penuh rasa

terima kasih.Akhir kata, Penyusun berharap laporan dan produk aplikasi ini dapat

bermanfaat bagi para pembaca, khususnya bagi yang akan mempelajari bahasa

pemrograman Java.

Yogyakarta, April 2012

Tim Penyusun

Page 4: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 4

PEMBAHASAN

1. ANALISA MASALAH

Toko Buku Murah Meriah memiliki banyak buku yang disimpan di took tersebut.

Masing-masing buku mempunyai judul, harga, pengarang dan kode yang unik. Buku-

buku tersebut juga dikelompokkan pada masing-masing kategori. Pada kasus ini,

setiap buku tersebut harus diinventarisir dan tercatat dalam system. Apabila

pencatatan dilakukan secara manual dikhawatirkan akan terjadi hal-hal yang tidak

diinginkan, missal buku catatan hilang dsb. Selain itu pada pencatatan secara

manual, jika buku yang ada sudah terlalu banyak maka akan terjadi kesulitan dalam

hal pencarian buku tertentu. Oleh karena itu, buku-buku tersebut akan diinventarisir

dan dicatat dalam system dengan database MySQL. Untuk memudahkan

pengolahan data (input, delete dan show data), maka perlu dibuat sebuah aplikasi

yang user-friendly dengan menggunakan JAVA.

Page 5: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 5

2. DESAIN DATABASE

Database yang akan digunakan dalam sistem toko buku murah meriah adalah

berikut ini:

Nama database : tbmurahmeriah

Platform : MySQL

Tabel : - buku

- kategori

- penerbit

Struktur Tabel Buku:

Field Tipe Data Lebar Keterangan

kd_buku Varchar 6 Primary key

Judul Varchar 50

Pengarang Varchar 50

kd_kategori Varchar 6

kd_penerbit Varchar 6

Harga Double

Struktur Tabel Kategori:

Field Tipe Data Lebar Keterangan

kd_kategori Varchar 6 Primary key

nama_kategori Varchar 50

Struktur Tabel Penerbit:

Field Tipe Data Lebar Keterangan

kd_penerbit Varchar 6 Primary key

nama_penerbit Varchar 50

alamat Varchar 100

Page 6: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 6

3. SOLUSI APLIKASI

a. DESKRIPSI

Aplikasi yang kita bangun untuk mengakomodasi kebutuhan Toko Buku

Murah Meriah terdiri dari sebuah program utama (main) yang mempunyai 4

menu sub program yaitu :

1. Data Buku

Adalah Sub Bagian mengolah data buku yang ada.

2. Data Kategori

Adalah Sub Bagian yang digunakan untuk mengolah data kategori buku

yang ada di toko buku Murah Meriah

3. Data Penerbit

Adalah Sub Bagian yang digunakan untuk mengolah data penerbit

4. Laporan Buku

Untuk menampilkan report atau laporan data buku di toko buku murah

meriah.

b. DESAIN MENU

- File

- Db Konfig

- Exit

- Master

- Data Buku

- Data Kategori

- Data Penerbit

- Laporan

- Laporan Buku

- About

c. DETAIL PROJECT

Program yang kita bangun memiliki bagian sebagai berikut :

1. Data Buku

adalah program untuk mengolah data buku, terdiri dari:

a. FormBuku.java

Form yang digunakan sebagai interface utama mengolah data buku.

Source code FormBuku.java:

/*

* To change this template, choose Tools | Templates

Page 7: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 7

* and open the template in the editor.

*/

/*

* FormBuku.java

*

* Created on 05 Jul 12, 18:36:22

*/

package elradesktopapplication;

import com.util.Utility;

import java.sql.Connection;

import javax.swing.JOptionPane;

import model.objBuku;

/**

*

* @author smpmuh2depok

*/

public class FormBuku extends javax.swing.JInternalFrame {

private Connection jKonek;

private boolean append;

private objBuku BukuModel;

/** Creates new form FormBuku */

private void clearForm(){

tfNIP.setText("");

tfNama.setText("");

tfAlamat.setText("");

cbo_bagian.setSelectedIndex(-1);

cbo_bagian1.setSelectedIndex(-1);

tfAlamat1.setText("");

}

void disableInput(boolean value){

tfNIP.setEnabled(! value);

tfNama.setEnabled(! value);

tfAlamat.setEnabled(! value);

cbo_bagian.setEnabled(! value);

cbo_bagian1.setEnabled(! value);

tfAlamat1.setEnabled(! value);

}

private void firstDisplay(){

clearForm();

disableInput(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.setEnabled(true);

btHapus.setEnabled(true);

btEdit.setEnabled(true);

}

private void initForm(){

BukuModel = new objBuku();

BukuModel.setConnection(jKonek);

cbo_bagian.setConnection(jKonek);

cbo_bagian.setQueryList("select kd_kategori, nama_kategori from kategori");

cbo_bagian.iniCombo();

cbo_bagian1.setConnection(jKonek);

cbo_bagian1.setQueryList("select kd_penerbit, nama_penerbit from penerbit");

cbo_bagian1.iniCombo();

firstDisplay();

}

private boolean saved(){

Page 8: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 8

boolean jSaved=false;

try {

BukuModel.kd_buku = String.valueOf(tfNIP.getText());

BukuModel.judul = String.valueOf(tfNama.getText());

BukuModel.pengarang = String.valueOf(tfAlamat.getText());

BukuModel.kd_kategori = Integer.valueOf(cbo_bagian.getSelectedIndex());

BukuModel.kd_penerbit = Integer.valueOf(cbo_bagian1.getSelectedIndex());

BukuModel.harga = String.valueOf(tfAlamat1.getText());

BukuModel.isInsert = append;

jSaved = BukuModel.saveBuku();

}

catch( Exception sqle) {

JOptionPane.showMessageDialog(this,

"Proses gagal:" +sqle, "Informasi", 0);

}

return jSaved;

}

public FormBuku(Connection vConnect) {

initComponents();

jKonek = vConnect;

initForm();

}

private void displayData(String vKode){

if (BukuModel.getBuku(vKode) ==false) return;

tfNIP.setText(BukuModel.kd_buku);

tfNama.setText(BukuModel.judul);

tfAlamat.setText(BukuModel.pengarang);

cbo_bagian.setSelectedIndex(Integer.valueOf (BukuModel.kd_kategori));

cbo_bagian1.setSelectedIndex(Integer.valueOf (BukuModel.kd_penerbit));

tfAlamat1.setText(BukuModel.harga);

}

/** 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() {

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

btTambah = new javax.swing.JButton();

btEdit = new javax.swing.JButton();

btBatal = new javax.swing.JButton();

btSimpan = new javax.swing.JButton();

btHapus = new javax.swing.JButton();

cbo_bagian = new com.uiElra.ComboUI();

tfAlamat = new javax.swing.JTextField();

tfNama = new javax.swing.JTextField();

tfNIP = new javax.swing.JTextField();

jLabel5 = new javax.swing.JLabel();

cbo_bagian1 = new com.uiElra.ComboUI();

jLabel6 = new javax.swing.JLabel();

tfAlamat1 = new javax.swing.JTextField();

jButton1 = new javax.swing.JButton();

Page 9: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 9

setName("Form"); // NOI18N

org.jdesktop.application.ResourceMap resourceMap =

org.jdesktop.application.Application.getInstance(elradesktopapplication.ElraDesktopApp.class).g

etContext().getResourceMap(FormBuku.class);

jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N

jLabel1.setName("jLabel1"); // NOI18N

jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N

jLabel2.setName("jLabel2"); // NOI18N

jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N

jLabel3.setName("jLabel3"); // NOI18N

jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N

jLabel4.setName("jLabel4"); // NOI18N

btTambah.setText(resourceMap.getString("btTambah.text")); // NOI18N

btTambah.setName("btTambah"); // NOI18N

btTambah.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btTambahActionPerformed(evt);

}

});

btEdit.setText(resourceMap.getString("btEdit.text")); // NOI18N

btEdit.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

btEdit.setName("btEdit"); // NOI18N

btEdit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btEditActionPerformed(evt);

}

});

btBatal.setText(resourceMap.getString("btBatal.text")); // NOI18N

btBatal.setName("btBatal"); // NOI18N

btBatal.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btBatalActionPerformed(evt);

}

});

btSimpan.setText(resourceMap.getString("btSimpan.text")); // NOI18N

btSimpan.setName("btSimpan"); // NOI18N

btSimpan.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btSimpanActionPerformed(evt);

}

});

btHapus.setText(resourceMap.getString("btHapus.text")); // NOI18N

btHapus.setName("btHapus"); // NOI18N

btHapus.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btHapusActionPerformed(evt);

}

});

cbo_bagian.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1",

"Item 2", "Item 3", "Item 4" }));

cbo_bagian.setColumnList(2);

cbo_bagian.setName("cbo_kategori"); // NOI18N

tfAlamat.setText(resourceMap.getString("tfAlamat.text")); // NOI18N

tfAlamat.setName("tfAlamat"); // NOI18N

Page 10: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 10

tfNama.setText(resourceMap.getString("tfNama.text")); // NOI18N

tfNama.setName("tfNama"); // NOI18N

tfNIP.setText(resourceMap.getString("tfNIP.text")); // NOI18N

tfNIP.setName("tfNIP"); // NOI18N

jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N

jLabel5.setName("jLabel5"); // NOI18N

cbo_bagian1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1",

"Item 2", "Item 3", "Item 4" }));

cbo_bagian1.setColumnList(2);

cbo_bagian1.setName("cbo_penerbit"); // NOI18N

jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N

jLabel6.setName("jLabel6"); // NOI18N

tfAlamat1.setText(resourceMap.getString("tfHarga.text")); // NOI18N

tfAlamat1.setName("tfHarga"); // NOI18N

jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N

jButton1.setName("jButton1"); // NOI18N

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(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()

.addContainerGap(39, Short.MAX_VALUE)

.addComponent(btTambah)

.addGap(4, 4, 4)

.addComponent(btEdit)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btBatal)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btSimpan)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btHapus)

.addGap(34, 34, 34))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(70, 70, 70)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jLabel4)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jLabel1)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jLabel5)

.addComponent(jLabel3)))))

.addGroup(layout.createSequentialGroup()

.addGap(79, 79, 79)

.addComponent(jLabel6)))

.addGap(2, 2, 2)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

Page 11: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 11

.addComponent(tfAlamat1, javax.swing.GroupLayout.DEFAULT_SIZE, 199,

Short.MAX_VALUE)

.addGap(81, 81, 81))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(cbo_bagian1, javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(cbo_bagian, javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(tfNama)

.addComponent(tfNIP, javax.swing.GroupLayout.DEFAULT_SIZE, 123,

Short.MAX_VALUE)

.addComponent(tfAlamat, javax.swing.GroupLayout.DEFAULT_SIZE, 199,

Short.MAX_VALUE))

.addContainerGap(81, Short.MAX_VALUE))))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

.addContainerGap(365, Short.MAX_VALUE)

.addComponent(jButton1))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(22, 22, 22)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(tfNIP, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel1))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(tfNama, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel3)

.addComponent(tfAlamat, 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(cbo_bagian, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel5))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel4)

.addComponent(cbo_bagian1, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel6)

.addComponent(tfAlamat1, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addComponent(jButton1))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18,

Short.MAX_VALUE)

Page 12: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 12

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(btTambah)

.addComponent(btEdit)

.addComponent(btBatal)

.addComponent(btSimpan)

.addComponent(btHapus))

.addGap(28, 28, 28))

);

pack();

}// </editor-fold>

private void btTambahActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

append=true;

clearForm();

disableInput(false);

btSimpan.setEnabled(true);

btBatal.setEnabled(true);

btTambah.setEnabled(false);

btEdit.setEnabled(false);

btHapus.setEnabled(false);

}

private void btEditActionPerformed(java.awt.event.ActionEvent evt) {

FormPencarian frm =new FormPencarian(null, false);

frm.setConnection(jKonek);

frm.setField1("kd_buku");

frm.setField2("judul");

frm.setLabelField1("Kode");

frm.setLabelField2("Judul");

frm.setTableName("buku");

frm.initForm();

frm.setVisible(true);

if (!frm.getKodePilih().equals("")) {

System.out.println(frm.getKodePilih());

append = false;

clearForm();

disableInput(false);

displayData(frm.getKodePilih());

btTambah.setEnabled(false);

btEdit.setEnabled(false);

btSimpan.setEnabled(true);

btBatal.setEnabled(true);

btHapus.setEnabled(false);

tfNIP.requestFocus();

}

frm.dispose();

}

private void btBatalActionPerformed(java.awt.event.ActionEvent evt) {

clearForm();

disableInput(true);

btTambah.setEnabled(true);

btTambah.requestFocus();

btEdit.setEnabled(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btHapus.setEnabled(true);

Page 13: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 13

}

private void btSimpanActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

if (saved()) {

JOptionPane.showMessageDialog(this,

"Data tersimpan", "Informasi", 1);

clearForm();

disableInput(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.setEnabled(true);

btEdit.setEnabled(true);

btHapus.setEnabled(true);

}

}

private void btHapusActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

FormPencarian frm =new FormPencarian(null, false);

frm.setConnection(jKonek);

frm.setField1("kd_buku");

frm.setField2("judul");

frm.setLabelField1("Kode ");

frm.setLabelField2("Judul ");

frm.setTableName("buku");

frm.initForm();

frm.setVisible(true);

if (!frm.getKodePilih().equals("")) {

int mDialog;

BukuModel.getBuku(frm.getKodePilih());

mDialog = (

JOptionPane.showConfirmDialog(

this, "Anda yakin mau menghapus "+

BukuModel.judul,

"Konfirmasi", 2));

if (mDialog==0) {

BukuModel.deleteBuku(

frm.getKodePilih());

}

btTambah.setEnabled(true);

btEdit.setEnabled(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.requestFocus();

}

frm.dispose();

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

this.setVisible(false);

}

// Variables declaration - do not modify

private javax.swing.JButton btBatal;

private javax.swing.JButton btEdit;

private javax.swing.JButton btHapus;

private javax.swing.JButton btSimpan;

private javax.swing.JButton btTambah;

Page 14: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 14

private com.uiElra.ComboUI cbo_bagian;

private com.uiElra.ComboUI cbo_bagian1;

private javax.swing.JButton jButton1;

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.JLabel jLabel6;

private javax.swing.JTextField tfAlamat;

private javax.swing.JTextField tfAlamat1;

private javax.swing.JTextField tfNIP;

private javax.swing.JTextField tfNama;

// End of variables declaration

}

b. objBuku

adalah class untuk olah data pada FormBuku.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package model;

import com.dbElra.DBQuery;

import java.sql.Connection;

/**

*

* @author smpmuh2depok

*/

public class objBuku {

private Connection jKonek;

public boolean isInsert = true;

public String kd_buku;

public String judul;

public String pengarang;

public Integer kd_kategori;

public Integer kd_penerbit;

public String harga;

public String ExceptionMessage=" haaaloo ";

public objBuku(){}

public void setConnection(Connection vConn){ jKonek= vConn;}

public boolean saveBuku() {

boolean result=false;

Page 15: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 15

String strQuerykat="";

DBQuery q = new DBQuery();

q.setConnection(jKonek);

if (isInsert==true)

strQuerykat="insert into buku set ";

else

strQuerykat="update buku set ";

strQuerykat=strQuerykat + " judul=?"+

", pengarang=? "+

", kd_kategori=? "+

", kd_penerbit=? "+

", harga=? ";

if (isInsert==true)

strQuerykat=strQuerykat +", kd_buku=? ";

else

strQuerykat=strQuerykat +" where kd_buku=? ";

q.setStrSql(strQuerykat);

q.preparedStatement();

try {

q.params().setString(6, kd_buku);

q.params().setString(5, harga);

q.params().setInt(4, kd_penerbit);

q.params().setInt(3, kd_kategori);

q.params().setString(2, pengarang);

q.params().setString(1, judul);

q.params().executeUpdate();

result=true;

}

catch(Exception e){

System.out.println(e);

}

return result;

}

public boolean getBuku(String vID) {

boolean result=false;

String strQ="";

String FieldList= "judul"+

", kd_buku"+

", pengarang";

strQ="select "+ FieldList +

" from buku" +

" where kd_buku='" + vID + "'";

Page 16: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 16

try {

DBQuery q = new DBQuery();

q.setConnection(jKonek);

q.setStrSql(strQ);

q.makeResulset();

if (q.next()==false) return false;

kd_buku = vID;

judul=q.getString(1);

pengarang=q.getString(2);

result=true;

}catch(Exception e){

System.out.println(e);

}

return result;

}

public boolean deleteBuku(String vID) {

boolean result=false;

try{

DBQuery q = new DBQuery();

q.setConnection(jKonek);

q.setStrSql("delete from buku"+

" where kd_buku='" + vID + "'");

q.preparedStatement();

q.executeUpdate();

result=true;

}catch (Exception e){

}

return result;

}

}

2. Data Kategori

adalah program untuk mengolah data kategori, terdiri dari:

a. FormKategori.java

Form yang digunakan sebagai interface utama mengolah data

kategori.

Source code Formkategori.java:

/*

* To change this template, choose Tools | Templates

Page 17: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 17

* and open the template in the editor.

*/

/*

* FormKategori.java

*

* Created on 05 Jul 12, 14:45:10

*/

package elradesktopapplication;

import com.util.Utility;

import java.sql.Connection;

import javax.swing.JOptionPane;

import model.objKategori;

/**

*

* @author smpmuh2depok

*/

public class FormKategori extends javax.swing.JInternalFrame {

private Connection jKonek;

private boolean append;

private objKategori KategoriModel;

/** Creates new form FormKategori */

private void clearForm(){

tfNIP.setText("");

tfNama.setText("");

}

void disableInput(boolean value){

tfNIP.setEnabled(! value);

tfNama.setEnabled(! value);

}

private void firstDisplay(){

clearForm();

disableInput(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.setEnabled(true);

btHapus.setEnabled(true);

btEdit.setEnabled(true);

}

private void initForm(){

KategoriModel = new objKategori();

KategoriModel.setConnection(jKonek);

firstDisplay();

}

private boolean saved(){

Page 18: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 18

boolean jSaved=false;

try {

KategoriModel.kd_kategori = String.valueOf(tfNIP.getText());

KategoriModel.nama_kategori = String.valueOf(tfNama.getText());

KategoriModel.isInsert = append;

jSaved = KategoriModel.saveKategori();

}

catch( Exception sqle) {

JOptionPane.showMessageDialog(this,

"Proses gagal:" +sqle, "Informasi", 0);

}

return jSaved;

}

public FormKategori(Connection vConnect) {

initComponents();

jKonek = vConnect;

initForm();

}

private void displayData(String vKode){

if (KategoriModel.getKategori(vKode) ==false) return;

tfNIP.setText(KategoriModel.kd_kategori);

tfNama.setText(KategoriModel.nama_kategori);

}

/** 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() {

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

tfNama = new javax.swing.JTextField();

tfNIP = new javax.swing.JTextField();

btTambah = new javax.swing.JButton();

btEdit = new javax.swing.JButton();

btBatal = new javax.swing.JButton();

btSimpan = new javax.swing.JButton();

btHapus = new javax.swing.JButton();

jButton1 = new javax.swing.JButton();

Page 19: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 19

org.jdesktop.application.ResourceMap resourceMap =

org.jdesktop.application.Application.getInstance(elradesktopapplication.ElraDesktopApp.class).g

etContext().getResourceMap(FormKategori.class);

setTitle(resourceMap.getString("frmKategori.title")); // NOI18N

setName("frmKategori"); // NOI18N

jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N

jLabel1.setName("jLabel1"); // NOI18N

jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N

jLabel2.setName("jLabel2"); // NOI18N

tfNama.setText(resourceMap.getString("tfNama.text")); // NOI18N

tfNama.setName("tfNama"); // NOI18N

tfNIP.setText(resourceMap.getString("tfNIP.text")); // NOI18N

tfNIP.setName("tfNIP"); // NOI18N

btTambah.setText(resourceMap.getString("btTambah.text")); // NOI18N

btTambah.setName("btTambah"); // NOI18N

btTambah.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btTambahActionPerformed(evt);

}

});

btEdit.setText(resourceMap.getString("btEdit.text")); // NOI18N

btEdit.setName("btEdit"); // NOI18N

btEdit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btEditActionPerformed(evt);

}

});

btBatal.setText(resourceMap.getString("btBatal.text")); // NOI18N

btBatal.setName("btBatal"); // NOI18N

btBatal.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btBatalActionPerformed(evt);

}

});

btSimpan.setText(resourceMap.getString("btSimpan.text")); // NOI18N

btSimpan.setName("btSimpan"); // NOI18N

btSimpan.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btSimpanActionPerformed(evt);

}

});

Page 20: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 20

btHapus.setText(resourceMap.getString("btHapus.text")); // NOI18N

btHapus.setName("btHapus"); // NOI18N

btHapus.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btHapusActionPerformed(evt);

}

});

jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N

jButton1.setName("jButton1"); // NOI18N

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(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()

.addContainerGap(355, Short.MAX_VALUE)

.addComponent(jButton1))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(31, 31, 31)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(16, 16, 16)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jLabel1)))

.addComponent(btTambah))

.addGap(4, 4, 4)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(btEdit)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btBatal)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btSimpan)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btHapus))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(tfNama)

Page 21: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 21

.addComponent(tfNIP, javax.swing.GroupLayout.DEFAULT_SIZE, 123,

Short.MAX_VALUE)))

.addContainerGap(17, Short.MAX_VALUE)))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jButton1)

.addContainerGap(263, Short.MAX_VALUE))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(46, 46, 46)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(tfNIP, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel1))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(tfNama, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2))

.addGap(104, 104, 104)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(btTambah)

.addComponent(btEdit)

.addComponent(btBatal)

.addComponent(btSimpan)

.addComponent(btHapus))

.addContainerGap(55, Short.MAX_VALUE)))

);

pack();

}// </editor-fold>

private void btTambahActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

append=true;

clearForm();

disableInput(false);

btSimpan.setEnabled(true);

btBatal.setEnabled(true);

btTambah.setEnabled(false);

btEdit.setEnabled(false);

btHapus.setEnabled(false);

}

Page 22: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 22

private void btEditActionPerformed(java.awt.event.ActionEvent evt) {

FormPencarian frm =new FormPencarian(null, false);

frm.setConnection(jKonek);

frm.setField1("kd_kategori");

frm.setField2("nama_kategori");

frm.setLabelField1("Kode Kategori");

frm.setLabelField2("Nama Kategori");

frm.setTableName("kategori");

frm.initForm();

frm.setVisible(true);

if (!frm.getKodePilih().equals("")) {

System.out.println(frm.getKodePilih());

append = false;

clearForm();

disableInput(false);

displayData(frm.getKodePilih());

btTambah.setEnabled(false);

btEdit.setEnabled(false);

btSimpan.setEnabled(true);

btBatal.setEnabled(true);

btHapus.setEnabled(false);

tfNIP.requestFocus();

}

frm.dispose();

}

private void btBatalActionPerformed(java.awt.event.ActionEvent evt) {

clearForm();

disableInput(true);

btTambah.setEnabled(true);

btTambah.requestFocus();

btEdit.setEnabled(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btHapus.setEnabled(true);

}

private void btSimpanActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

if (saved()) {

JOptionPane.showMessageDialog(this,

"Data tersimpan", "Informasi", 1);

clearForm();

disableInput(true);

Page 23: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 23

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.setEnabled(true);

btEdit.setEnabled(true);

btHapus.setEnabled(true);

}

}

private void btHapusActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

FormPencarian frm =new FormPencarian(null, false);

frm.setConnection(jKonek);

frm.setField1("kd_kategori");

frm.setField2("nama_kategori");

frm.setLabelField1("Kode ");

frm.setLabelField2("Nama ");

frm.setTableName("kategori");

frm.initForm();

frm.setVisible(true);

if (!frm.getKodePilih().equals("")) {

int mDialog;

KategoriModel.getKategori(frm.getKodePilih());

mDialog = (

JOptionPane.showConfirmDialog(

this, "Anda yakin mau menghapus "+

KategoriModel.nama_kategori,

"Konfirmasi", 2));

if (mDialog==0) {

KategoriModel.deleteKategori(

frm.getKodePilih());

}

btTambah.setEnabled(true);

btEdit.setEnabled(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.requestFocus();

}

frm.dispose();

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

this.setVisible(false);

}

Page 24: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 24

// Variables declaration - do not modify

private javax.swing.JButton btBatal;

private javax.swing.JButton btEdit;

private javax.swing.JButton btHapus;

private javax.swing.JButton btSimpan;

private javax.swing.JButton btTambah;

private javax.swing.JButton jButton1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JTextField tfNIP;

private javax.swing.JTextField tfNama;

// End of variables declaration

}

b. ObjKategori

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package model;

import com.dbElra.DBQuery;

import java.sql.Connection;

/**

*

* @author smpmuh2depok

*/

public class objKategori {

private Connection jKonek;

public boolean isInsert = true;

public String kd_kategori;

public String nama_kategori;

public String ExceptionMessage=" haaaloo ";

public objKategori(){}

public void setConnection(Connection vConn){ jKonek= vConn;}

public boolean saveKategori() {

boolean result=false;

String strQuerykat="";

DBQuery q = new DBQuery();

q.setConnection(jKonek);

if (isInsert==true)

Page 25: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 25

strQuerykat="insert into kategori set ";

else

strQuerykat="update kategori set ";

strQuerykat=strQuerykat + " nama_kategori=? ";

if (isInsert==true)

strQuerykat=strQuerykat +", kd_kategori=? ";

else

strQuerykat=strQuerykat +" where kd_kategori=? ";

q.setStrSql(strQuerykat);

q.preparedStatement();

try {

q.params().setString(2, kd_kategori);

q.params().setString(1, nama_kategori);

q.params().executeUpdate();

result=true;

}

catch(Exception e){

System.out.println(e);

}

return result;

}

public boolean getKategori(String vID) {

boolean result=false;

String strQ="";

String FieldList= "nama_kategori"+

", kd_kategori";

strQ="select "+ FieldList +

" from kategori" +

" where kd_kategori='" + vID + "'";

try {

DBQuery q = new DBQuery();

q.setConnection(jKonek);

q.setStrSql(strQ);

q.makeResulset();

if (q.next()==false) return false;

kd_kategori = vID;

nama_kategori=q.getString(1);

result=true;

}catch(Exception e){

System.out.println(e);

}

Page 26: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 26

return result;

}

public boolean deleteKategori(String vID) {

boolean result=false;

try{

DBQuery q = new DBQuery();

q.setConnection(jKonek);

q.setStrSql("delete from kategori"+

" where kd_kategori='" + vID + "'");

q.preparedStatement();

q.executeUpdate();

result=true;

}catch (Exception e){

}

return result;

}

}

3. Data Penerbit

adalah program untuk mengolah data penerbit, terdiri dari:

a. FormPenerbit.java

Form yang digunakan sebagai interface utama mengolah data

penerbit.

Source code FormPenerbit.java:

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/*

* FormPenerbit.java

*

* Created on 05 Jul 12, 18:00:50

*/

package elradesktopapplication;

import com.util.Utility;

import java.sql.Connection;

import javax.swing.JOptionPane;

/**

*

Page 27: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 27

* @author smpmuh2depok

*/

import model.objPenerbit;

public class FormPenerbit extends javax.swing.JInternalFrame {

private Connection jKonek;

private boolean append;

private objPenerbit PenerbitModel;

/** Creates new form FormPenerbit */

private void clearForm(){

tfNIP.setText("");

tfNama.setText("");

tfAlamat.setText("");

}

void disableInput(boolean value){

tfNIP.setEnabled(! value);

tfNama.setEnabled(! value);

tfAlamat.setEnabled(! value);

}

private void firstDisplay(){

clearForm();

disableInput(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.setEnabled(true);

btHapus.setEnabled(true);

btEdit.setEnabled(true);

}

private void initForm(){

PenerbitModel = new objPenerbit();

PenerbitModel.setConnection(jKonek);

firstDisplay();

}

private boolean saved(){

boolean jSaved=false;

try {

PenerbitModel.kd_penerbit = String.valueOf(tfNIP.getText());

PenerbitModel.nama_penerbit = String.valueOf(tfNama.getText());

PenerbitModel.alamat = String.valueOf(tfAlamat.getText());

PenerbitModel.isInsert = append;

jSaved = PenerbitModel.savePenerbit();

}

catch( Exception sqle) {

JOptionPane.showMessageDialog(this,

"Proses gagal:" +sqle, "Informasi", 0);

}

Page 28: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 28

return jSaved;

}

public FormPenerbit(Connection vConnect) {

initComponents();

jKonek = vConnect;

initForm();

}

private void displayData(String vKode){

if (PenerbitModel.getPenerbit(vKode) ==false) return;

tfNIP.setText(PenerbitModel.kd_penerbit);

tfNama.setText(PenerbitModel.nama_penerbit);

tfAlamat.setText(PenerbitModel.alamat);

}

/** 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">//GEN-

BEGIN:initComponents

private void initComponents() {

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

tfAlamat = new javax.swing.JTextField();

tfNama = new javax.swing.JTextField();

tfNIP = new javax.swing.JTextField();

btHapus = new javax.swing.JButton();

btSimpan = new javax.swing.JButton();

btBatal = new javax.swing.JButton();

btEdit = new javax.swing.JButton();

btTambah = new javax.swing.JButton();

jButton1 = new javax.swing.JButton();

setName("FormPenerbit"); // NOI18N

org.jdesktop.application.ResourceMap resourceMap =

org.jdesktop.application.Application.getInstance(elradesktopapplication.ElraDesktopApp.class).g

etContext().getResourceMap(FormPenerbit.class);

jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N

jLabel1.setName("jLabel1"); // NOI18N

Page 29: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 29

jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N

jLabel2.setName("jLabel2"); // NOI18N

jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N

jLabel3.setName("jLabel3"); // NOI18N

tfAlamat.setText(resourceMap.getString("tfAlamat.text")); // NOI18N

tfAlamat.setName("tfAlamat"); // NOI18N

tfNama.setText(resourceMap.getString("tfNama.text")); // NOI18N

tfNama.setName("tfNama"); // NOI18N

tfNIP.setText(resourceMap.getString("tfNIP.text")); // NOI18N

tfNIP.setName("tfNIP"); // NOI18N

btHapus.setText(resourceMap.getString("btHapus.text")); // NOI18N

btHapus.setName("btHapus"); // NOI18N

btHapus.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btHapusActionPerformed(evt);

}

});

btSimpan.setText(resourceMap.getString("btSimpan.text")); // NOI18N

btSimpan.setName("btSimpan"); // NOI18N

btSimpan.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btSimpanActionPerformed(evt);

}

});

btBatal.setText(resourceMap.getString("btBatal.text")); // NOI18N

btBatal.setName("btBatal"); // NOI18N

btBatal.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btBatalActionPerformed(evt);

}

});

btEdit.setText(resourceMap.getString("btEdit.text")); // NOI18N

btEdit.setName("btEdit"); // NOI18N

btEdit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btEditActionPerformed(evt);

}

});

btTambah.setText(resourceMap.getString("btTambah.text")); // NOI18N

btTambah.setName("btTambah"); // NOI18N

btTambah.addActionListener(new java.awt.event.ActionListener() {

Page 30: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 30

public void actionPerformed(java.awt.event.ActionEvent evt) {

btTambahActionPerformed(evt);

}

});

jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N

jButton1.setName("jButton1"); // NOI18N

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(31, 31, 31)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(16, 16, 16)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jLabel3)

.addComponent(jLabel1)))

.addComponent(btTambah))

.addGap(4, 4, 4)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(btEdit)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btBatal)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btSimpan)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btHapus))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(tfNama)

.addComponent(tfNIP, javax.swing.GroupLayout.DEFAULT_SIZE, 123,

Short.MAX_VALUE)

.addComponent(tfAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 199,

javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(20, Short.MAX_VALUE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

.addContainerGap(355, Short.MAX_VALUE)

.addComponent(jButton1))

Page 31: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 31

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jButton1)

.addGap(10, 10, 10)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(tfNIP, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel1))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(tfNama, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel3)

.addComponent(tfAlamat, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(66, 66, 66)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(btTambah)

.addComponent(btEdit)

.addComponent(btBatal)

.addComponent(btSimpan)

.addComponent(btHapus))

.addContainerGap(64, Short.MAX_VALUE))

);

pack();

}// </editor-fold>//GEN-END:initComponents

private void btHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_btHapusActionPerformed

// TODO add your handling code here:

FormPencarian frm =new FormPencarian(null, false);

frm.setConnection(jKonek);

frm.setField1("Kode Penerbit");

frm.setField2("Nama");

frm.setLabelField1("Kode ");

frm.setLabelField2("Nama ");

frm.setTableName("penerbit");

frm.initForm();

Page 32: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 32

frm.setVisible(true);

if (!frm.getKodePilih().equals("")) {

int mDialog;

PenerbitModel.getPenerbit(frm.getKodePilih());

mDialog = (

JOptionPane.showConfirmDialog(

this, "Anda yakin mau menghapus "+

PenerbitModel.nama_penerbit,

"Konfirmasi", 2));

if (mDialog==0) {

PenerbitModel.deletePenerbit(

frm.getKodePilih());

}

btTambah.setEnabled(true);

btEdit.setEnabled(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.requestFocus();

}

frm.dispose();

}//GEN-LAST:event_btHapusActionPerformed

private void btSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_btSimpanActionPerformed

// TODO add your handling code here:

if (saved()) {

JOptionPane.showMessageDialog(this,

"Data tersimpan", "Informasi", 1);

clearForm();

disableInput(true);

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btTambah.setEnabled(true);

btEdit.setEnabled(true);

btHapus.setEnabled(true);

}

}//GEN-LAST:event_btSimpanActionPerformed

private void btBatalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_btBatalActionPerformed

clearForm();

disableInput(true);

btTambah.setEnabled(true);

btTambah.requestFocus();

btEdit.setEnabled(true);

Page 33: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 33

btSimpan.setEnabled(false);

btBatal.setEnabled(false);

btHapus.setEnabled(true);

}//GEN-LAST:event_btBatalActionPerformed

private void btEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_btEditActionPerformed

FormPencarian frm =new FormPencarian(null, false);

frm.setConnection(jKonek);

frm.setField1("IDStaff");

frm.setField2("nama");

frm.setLabelField1("NIK");

frm.setLabelField2("Nama");

frm.setTableName("staff");

frm.initForm();

frm.setVisible(true);

if (!frm.getKodePilih().equals("")) {

System.out.println(frm.getKodePilih());

append = false;

clearForm();

disableInput(false);

displayData(frm.getKodePilih());

btTambah.setEnabled(false);

btEdit.setEnabled(false);

btSimpan.setEnabled(true);

btBatal.setEnabled(true);

btHapus.setEnabled(false);

tfNIP.requestFocus();

}

frm.dispose();

}//GEN-LAST:event_btEditActionPerformed

private void btTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_btTambahActionPerformed

// TODO add your handling code here:

append=true;

clearForm();

disableInput(false);

btSimpan.setEnabled(true);

btBatal.setEnabled(true);

btTambah.setEnabled(false);

btEdit.setEnabled(false);

btHapus.setEnabled(false);

}//GEN-LAST:event_btTambahActionPerformed

Page 34: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 34

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_jButton1ActionPerformed

// TODO add your handling code here:

this.setVisible(false);

}//GEN-LAST:event_jButton1ActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JButton btBatal;

private javax.swing.JButton btEdit;

private javax.swing.JButton btHapus;

private javax.swing.JButton btSimpan;

private javax.swing.JButton btTambah;

private javax.swing.JButton jButton1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JTextField tfAlamat;

private javax.swing.JTextField tfNIP;

private javax.swing.JTextField tfNama;

// End of variables declaration//GEN-END:variables

}

b. objPenerbit

Class yang digunakan sebagai interface utama mengolah data

penerbit.

Source code objPenerbit :

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package model;

import com.dbElra.DBQuery;

import java.sql.Connection;

/**

*

* @author smpmuh2depok

*/

public class objPenerbit {

private Connection jKonek;

public boolean isInsert = true;

public String kd_penerbit;

public String nama_penerbit;

public String alamat;

public String ExceptionMessage=" ";

Page 35: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 35

public objPenerbit(){}

public void setConnection(Connection vConn){ jKonek= vConn;}

public boolean savePenerbit() {

boolean result=false;

String strQuerykat="";

DBQuery q = new DBQuery();

q.setConnection(jKonek);

if (isInsert==true)

strQuerykat="insert into penerbit set ";

else

strQuerykat="update penerbit set ";

strQuerykat=strQuerykat + " alamat=?"+

", nama_penerbit=? ";

if (isInsert==true)

strQuerykat=strQuerykat +", kd_penerbit=? ";

else

strQuerykat=strQuerykat +" where kd_penerbit=? ";

q.setStrSql(strQuerykat);

q.preparedStatement();

try {

q.params().setString(3, kd_penerbit);

q.params().setString(2, nama_penerbit);

q.params().setString(1, alamat);

q.params().executeUpdate();

result=true;

}

catch(Exception e){

System.out.println(e);

}

return result;

}

public boolean getPenerbit(String vID) {

boolean result=false;

String strQ="";

String FieldList= "nama_Penerbit"+

", kd_Penerbit";

strQ="select "+ FieldList +

" from Penerbit" +

" where kd_Penerbit='" + vID + "'";

Page 36: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 36

try {

DBQuery q = new DBQuery();

q.setConnection(jKonek);

q.setStrSql(strQ);

q.makeResulset();

if (q.next()==false) return false;

kd_penerbit = vID;

nama_penerbit=q.getString(1);

result=true;

}catch(Exception e){

System.out.println(e);

}

return result;

}

public boolean deletePenerbit(String vID) {

boolean result=false;

try{

DBQuery q = new DBQuery();

q.setConnection(jKonek);

q.setStrSql("delete from penerbit"+

" where kd_penerbit='" + vID + "'");

q.preparedStatement();

q.executeUpdate();

result=true;

}catch (Exception e){

}

return result;

}

}

d. SNAPSHOT

1. Main Program

Page 37: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 37

2. Form Data Buku

3. Form Data Kategori

Page 38: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 38

4. Form Data Penerbit

5. Laporan Buku

Page 39: LAPORAN KELOMPOK 14_TOKOMURAHMERIAH.pdf

Mata Kuliah : Pemrograman Java

Laporan-Kelompok-14-Toko-Murah-Meriah-STMIK-El-Rahma-2012 39