PROGRAM APLIKASI PENGIRIMAN BARANG
Nama : Rizqy Dwi Syahputra
Nik : 161021401417
Kelas : 05TPLM001
Assalamualaikum Wr. Wb.
Pada postingan ini saya akan memberikan tutorial cara membuat Aplikasi Pengiriman Barang yang terhubung dengan database di program Netbean Java.
Tutorialnya :
1. Buka Program XAMPP, pastikan module "Apache" dan "MySQL" sudah di start seperti contoh dibawah ini.
2. Kemudian Buka Program SQLlog dan pastikan sudah terkoneksi seperti ini
3. Klik kanan pada root lalu pilih create database, beri nama "db_pengiriman_barang" lalu klik create
4. Lalu create table dengan nama "tb_jenis_paket" "tb_penerima_barang" "tb_pengirim" "tb_pengiriman_barang" "tb_petugas", beri nama variable seperti berikut
Apabila sudah maka klik simpan
5. Buka Program netbean dan mulai create new Project seperti dibawah ini
6. Sebelum mulai projectnya, kita masukkan dulu libaries "mySql" supaya terhubung dengan databasenya dengan cara sebagai berikut.
FORM MAIN
1. Klik Kanan Java Source Code Package "Form_Pengiriman_Barang" lalu buat form "Main" seperti berikut
2. Sudah selesai, maka kita harus buat Formnya seperti berikut ini
4. Lalu pada tabel palette, insert label dan jButton dengan keterangan sebagai berikut :
- Label1 = Aplikasi Pengiriman Barang
- jButton1 = Form Petugas
- jButton2 = Form Jenis Paket
- jButton3 = Form Pengirim
- jButton4 = Form Pengiriman Barang
5. Jika sudah maka selanjutnya kita lalukan Event - Action untuk memberi fungsi pada jButtonya
6. Pada setiap jButton (ada 4) diberi codingan sebagai berikut
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Form_Petugas satu=new Form_Petugas();
satu.setVisible(true);
dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Form_Jenis_Paket dua=new Form_Jenis_Paket();
dua.setVisible(true);
dispose();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Form_Pengirim tiga=new Form_Pengirim();
tiga.setVisible(true);
dispose();
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Form_Pengiriman_Barang empat=new Form_Pengiriman_Barang();
empat.setVisible(true);
dispose();
}
FORM PETUGAS
1. Kemudian buat Jframe lagi seperti sebelumnya, beri nama Form_Petugas
2. Buat Formnya seperti ini
3. Maka kita buat variabelnya seperti berikut
- Label1 = ID Petugas
- Label2 = Nama Petugas
- ComboBox = Jabatan (Admin,Kurir,Driver)
- Label3 = Alamat
- Label4 = Telepon
- Tabel1 = gridPetugas
- jButton1 = Simpan
- jButton2 = Ubah
- jButton3 = Hapus
- jButton4 = Batal
- jButton5 = Keluar
6. Agar terhubung dengan database (tb_pengiriman_barang) maka kita harus masukkan source code di line 6
package Form_Pengiriman_Barang;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Petugas extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rspetugas;
private String sql="";
private String id,nama,jabatan,alamat,telepon;
/**
* Creates new form Form_Petugas
*/
public Form_Petugas() {
initComponents();
koneksikan();
tampildata("select * from tb_petugas");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
private void tampildata(String sql) {
DefaultTableModel datalist= new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("ID Petugas");
datalist.addColumn("Nama");
datalist.addColumn("Jabatan");
datalist.addColumn("Alamat");
datalist.addColumn("telepon");
try {
int i = 1;
st=con.createStatement();
rspetugas=st.executeQuery("select * from tb_petugas");
while (rspetugas.next()) {
datalist.addRow(new Object[]{
(""+i++),rspetugas.getString(1),
rspetugas.getString(2),rspetugas.getString(3),
rspetugas.getString(4),
rspetugas.getString(5)
});
gridpetugas.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void kosongkan(){
txtid.setText("");
txtnama.setText("");
txtjabatan.setSelectedItem("-pilih-");
txtalamat.setText("");
txttelepon.setText("");
}
7. Kemudian kita langsung kerjakan jButton "Simpan,Ubah,Hapus,Batal,Keluar" dengan actionPerformed
8. Lalu kita mulai masukkan kodingannya seperti berikut
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=String.valueOf(txtid.getText());
nama=String.valueOf(txtnama.getText());
jabatan=txtjabatan.getItemAt(txtjabatan.getSelectedIndex()).toString();
alamat=String.valueOf(txtalamat.getText());
telepon=String.valueOf(txttelepon.getText());
try {
sql = "insert into tb_petugas(id_petugas,nama_petugas,jabatan,alamat,telepon)value ("
+ "'"+ id +"','"+ nama +"','"+ jabatan +"','"+ alamat +"','"+ telepon + "')";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_petugas");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal disimpan \n"+e.getMessage());
}
kosongkan();
}
private void btnubahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=String.valueOf(txtid.getText());
nama=String.valueOf(txtnama.getText());
jabatan=txtjabatan.getItemAt(txtjabatan.getSelectedIndex()).toString();
alamat=String.valueOf(txtalamat.getText());
telepon=String.valueOf(txttelepon.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah data ini mau diubah","konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION) {
try {
sql = "update tb_petugas set nama_petugas='" + nama + "',"
+ "jabatan='"+jabatan+"',alamat='"+alamat+"' where id_petugas='"+id+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_petugas");
JOptionPane.showMessageDialog(null, "data berhasil diubah");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal diubah \n"+e.getMessage());
}
}
}
private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=String.valueOf(txtid.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah anda yakin menghapus data ini","Konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION)
{
try {
sql="delete from tb_petugas where id_petugas='"+id+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_petugas");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal di hapus \n"+e.getMessage());
}
}
}
private void btnbatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kosongkan();
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(1);
}
9. Untuk memunculkan keterangan tabelnya, kita lakukan berikut ini
10. Masukkan Kodingannya sebagai berikut
private void gridpetugasMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
txtid.setText(String.valueOf(gridpetugas.getValueAt(gridpetugas.getSelectedRow(),1)));
txtnama.setText(String.valueOf(gridpetugas.getValueAt(gridpetugas.getSelectedRow(),2)));
txtjabatan.setSelectedItem(String.valueOf(gridpetugas.getValueAt(gridpetugas.getSelectedRow(),3)));
txtalamat.setText(String.valueOf(gridpetugas.getValueAt(gridpetugas.getSelectedRow(),4)));
txttelepon.setText(String.valueOf(gridpetugas.getValueAt(gridpetugas.getSelectedRow(),5)));
}
FORM JENIS PAKET
1. Buat JFrame "Form_Jenis_Paket", kita akan buat formnya seperti ini
2. Maka kita buat variabelnya seperti berikut
- Label1 = ID Paket
- ComboBox = Paket Type (Reguler,Kilat,Express)
- Label2 = Biaya
- Label3 = Asuransi
- Tabel4 = gridjenispaket
- TextField = txtidpaket
- TextField2 = txtbiaya
- TextField 3 = txtasuransi
- jButton1 = Simpan
- jButton2 = Ubah
- jButton3 = Hapus
- jButton4 = Batal
- jButton5 = Keluar
3. Untuk menghubungkan database (tb_jenis_paket) maka kita masukkan kodingannya di line 6
package Form_Pengiriman_Barang;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Jenis_Paket extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rspaket;
private String sql="";
private String id,type;
private int berat,biaya,asuransi;
/**
* Creates new form Form_Jenis_Paket
*/
public Form_Jenis_Paket() {
initComponents();
koneksikan();
tampildata("select * from tb_jenis_paket");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Jenis_Paket extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rspaket;
private String sql="";
private String id,type;
private int berat,biaya,asuransi;
/**
* Creates new form Form_Jenis_Paket
*/
public Form_Jenis_Paket() {
initComponents();
koneksikan();
tampildata("select * from tb_jenis_paket");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
private void tampildata(String sql) {
DefaultTableModel datalist= new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("ID Paket");
datalist.addColumn("Type");
datalist.addColumn("Biaya");
datalist.addColumn("Asuransi");
try {
int i = 1;
st=con.createStatement();
rspaket=st.executeQuery("select * from tb_jenis_paket");
while (rspaket.next()) {
datalist.addRow(new Object[]{
(""+i++),rspaket.getString(1),
rspaket.getString(2),rspaket.getString(3),
rspaket.getString(4),
});
gridjenispaket.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
DefaultTableModel datalist= new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("ID Paket");
datalist.addColumn("Type");
datalist.addColumn("Biaya");
datalist.addColumn("Asuransi");
try {
int i = 1;
st=con.createStatement();
rspaket=st.executeQuery("select * from tb_jenis_paket");
while (rspaket.next()) {
datalist.addRow(new Object[]{
(""+i++),rspaket.getString(1),
rspaket.getString(2),rspaket.getString(3),
rspaket.getString(4),
});
gridjenispaket.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void kosongkan(){
txtid.setText("");
txttype.setSelectedItem("-pilih-");
txtbiaya.setText("");
txtasuransi.setText("");
}
txtid.setText("");
txttype.setSelectedItem("-pilih-");
txtbiaya.setText("");
txtasuransi.setText("");
}
4. Kemudian kita langsung kerjakan jButton "Simpan,Ubah,Hapus,Batal,Keluar" dengan actionPerformed
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=String.valueOf(txtid.getText());
type=txttype.getItemAt(txttype.getSelectedIndex()).toString();
biaya=Integer.parseInt(txtbiaya.getText());
asuransi=Integer.parseInt(txtasuransi.getText());
try {
sql = "insert into tb_jenis_paket(id_paket,paket_type,biaya,asuransi)value ("
+ "'"+ id +"','"+ type +"','"+ biaya +"','"+ asuransi +"')";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_jenis_paket");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal disimpan \n"+e.getMessage());
}
kosongkan();
}
private void btnubahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=String.valueOf(txtid.getText());
type=txttype.getItemAt(txttype.getSelectedIndex()).toString();
biaya=Integer.parseInt(txtbiaya.getText());
asuransi=Integer.parseInt(txtasuransi.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah data ini mau diubah","konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION) {
try {
sql = "update tb_jenis_paket set id_paket='" + id + "',"
+ "paket_type='"+type+"',biaya='"+biaya+"' where id_paket='"+id+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_jenis_paket");
JOptionPane.showMessageDialog(null, "data berhasil diubah");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal diubah \n"+e.getMessage());
}
}
}
private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=String.valueOf(txtid.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah anda yakin menghapus data ini","Konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION)
{
try {
sql="delete from tb_jenis_paket where id_paket='"+id+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_jenis_paket");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal di hapus \n"+e.getMessage());
}
}
}
private void btnbatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kosongkan();
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(1);
}
6. Untuk memunculkan keterangan tabelnya, kita lakukan berikut ini
7. Masukkan Kodingannya sebagai berikut
private void gridjenispaketMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
txtid.setText(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),1)));
txttype.setSelectedItem(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),2)));
txtbiaya.setText(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),3)));
txtasuransi.setText(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),4)));
// TODO add your handling code here:
txtid.setText(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),1)));
txttype.setSelectedItem(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),2)));
txtbiaya.setText(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),3)));
txtasuransi.setText(String.valueOf(gridjenispaket.getValueAt(gridjenispaket.getSelectedRow(),4)));
}
FORM PENGIRIM
1. Buat JFrame "Form_Pengirim", kita akan buat formnya seperti ini
2. Maka kita buat variabelnya seperti berikut
- Label1 = No. Pengirim
- Label2 = Nama Pengirim
- Label3 = Alamat
- Label4 = KodePos
- Label5 = Kota
- Label6 = Provinsi
- Label7 = Daerah
- Label8 = Telepon
- TextArea1 = Alamat
- Tabel4 = gridpengirim
- TextField = txtno
- TextField2 = txtnama
- TextField 3 = txtkota
- TextField 3 = txtprovinsi
- TextField 3 = txtkodepos
- TextField 3 = txtdaerah
- TextField 3 = txttelepon
- jButton1 = Simpan
- jButton2 = Ubah
- jButton3 = Hapus
- jButton4 = Batal
- jButton5 = Keluar
3. Untuk menghubungkan database (tb_pengirim) maka kita masukkan kodingannya di line 6
package Form_Pengiriman_Barang;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Pengirim extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rspengirim;
private String sql="";
private String no,nama,alamat,kota,provinsi,kodepos,daerah,telepon;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Pengirim extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rspengirim;
private String sql="";
private String no,nama,alamat,kota,provinsi,kodepos,daerah,telepon;
/**
* Creates new form FormPengirim
*/
public Form_Pengirim() {
initComponents();
koneksikan();
tampildata("select * from tb_pengirim");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
* Creates new form FormPengirim
*/
public Form_Pengirim() {
initComponents();
koneksikan();
tampildata("select * from tb_pengirim");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
private void tampildata(String sql) {
DefaultTableModel datalist= new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("No Pengirim");
datalist.addColumn("Nama Pengirim");
datalist.addColumn("Alamat");
datalist.addColumn("Kota");
datalist.addColumn("Provinsi");
datalist.addColumn("Kode Pos");
datalist.addColumn("Daerah");
datalist.addColumn("Telepon");
try {
int i = 1;
st=con.createStatement();
rspengirim=st.executeQuery("select * from tb_pengirim");
while (rspengirim.next()) {
datalist.addRow(new Object[]{
(""+i++),rspengirim.getString(1),
rspengirim.getString(2),rspengirim.getString(3),
rspengirim.getString(4),
rspengirim.getString(5),
rspengirim.getString(6),
rspengirim.getString(7),
rspengirim.getString(8),
});
gridpengirim.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
DefaultTableModel datalist= new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("No Pengirim");
datalist.addColumn("Nama Pengirim");
datalist.addColumn("Alamat");
datalist.addColumn("Kota");
datalist.addColumn("Provinsi");
datalist.addColumn("Kode Pos");
datalist.addColumn("Daerah");
datalist.addColumn("Telepon");
try {
int i = 1;
st=con.createStatement();
rspengirim=st.executeQuery("select * from tb_pengirim");
while (rspengirim.next()) {
datalist.addRow(new Object[]{
(""+i++),rspengirim.getString(1),
rspengirim.getString(2),rspengirim.getString(3),
rspengirim.getString(4),
rspengirim.getString(5),
rspengirim.getString(6),
rspengirim.getString(7),
rspengirim.getString(8),
});
gridpengirim.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void kosongkan(){
txtno.setText("");
txtnama.setText("");
txtalamat.setText("");
txtkota.setText("");
txtprovinsi.setText("");
txtkodepos.setText("");
txtdaerah.setText("");
txttelepon.setText("");
}
txtno.setText("");
txtnama.setText("");
txtalamat.setText("");
txtkota.setText("");
txtprovinsi.setText("");
txtkodepos.setText("");
txtdaerah.setText("");
txttelepon.setText("");
}
4. Kemudian kita langsung kerjakan jButton "Simpan,Ubah,Hapus,Batal,Keluar" dengan actionPerformed
5. Lalu kita mulai masukkan kodingannya seperti berikut
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no=String.valueOf(txtno.getText());
nama=String.valueOf(txtnama.getText());
alamat=String.valueOf(txtalamat.getText());
kota=String.valueOf(txtkota.getText());
provinsi=String.valueOf(txtprovinsi.getText());
kodepos=String.valueOf(txtkodepos.getText());
daerah=String.valueOf(txtdaerah.getText());
telepon=String.valueOf(txttelepon.getText());
try {
sql = "insert into tb_pengirim(no_pengirim,nama_pengirim,alamat,kota,provinsi,kodepos,daerah,telepon)value ("
+ "'"+ no +"','"+ nama +"','"+ alamat +"','"+ kota +"','"+ provinsi +"','"+ kodepos +"','"+ daerah +"','"+ telepon + "')";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengirim");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal disimpan \n"+e.getMessage());
}
kosongkan();
}
// TODO add your handling code here:
no=String.valueOf(txtno.getText());
nama=String.valueOf(txtnama.getText());
alamat=String.valueOf(txtalamat.getText());
kota=String.valueOf(txtkota.getText());
provinsi=String.valueOf(txtprovinsi.getText());
kodepos=String.valueOf(txtkodepos.getText());
daerah=String.valueOf(txtdaerah.getText());
telepon=String.valueOf(txttelepon.getText());
try {
sql = "insert into tb_pengirim(no_pengirim,nama_pengirim,alamat,kota,provinsi,kodepos,daerah,telepon)value ("
+ "'"+ no +"','"+ nama +"','"+ alamat +"','"+ kota +"','"+ provinsi +"','"+ kodepos +"','"+ daerah +"','"+ telepon + "')";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengirim");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal disimpan \n"+e.getMessage());
}
kosongkan();
}
private void btnubahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no=String.valueOf(txtno.getText());
nama=String.valueOf(txtnama.getText());
alamat=String.valueOf(txtalamat.getText());
kota=String.valueOf(txtkota.getText());
provinsi=String.valueOf(txtprovinsi.getText());
kodepos=String.valueOf(txtkodepos.getText());
daerah=String.valueOf(txtdaerah.getText());
telepon=String.valueOf(txttelepon.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah data ini mau diubah","konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION) {
try {
sql = "update tb_pengirim set nama_pengirim='" + nama + "',"
+ "kota='"+kota+"',alamat='"+alamat+"' where no_pengirim='"+no+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengirim");
JOptionPane.showMessageDialog(null, "data berhasil diubah");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal diubah \n"+e.getMessage());
}
}
}
// TODO add your handling code here:
no=String.valueOf(txtno.getText());
nama=String.valueOf(txtnama.getText());
alamat=String.valueOf(txtalamat.getText());
kota=String.valueOf(txtkota.getText());
provinsi=String.valueOf(txtprovinsi.getText());
kodepos=String.valueOf(txtkodepos.getText());
daerah=String.valueOf(txtdaerah.getText());
telepon=String.valueOf(txttelepon.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah data ini mau diubah","konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION) {
try {
sql = "update tb_pengirim set nama_pengirim='" + nama + "',"
+ "kota='"+kota+"',alamat='"+alamat+"' where no_pengirim='"+no+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengirim");
JOptionPane.showMessageDialog(null, "data berhasil diubah");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal diubah \n"+e.getMessage());
}
}
}
private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no=String.valueOf(txtno.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah anda yakin menghapus data ini","Konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION)
{
try {
sql="delete from tb_pengirim where no_pengirim='"+no+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengirim");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal di hapus \n"+e.getMessage());
}
}
}
// TODO add your handling code here:
no=String.valueOf(txtno.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah anda yakin menghapus data ini","Konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION)
{
try {
sql="delete from tb_pengirim where no_pengirim='"+no+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengirim");
JOptionPane.showMessageDialog(null, "data berhasil disimpan");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal di hapus \n"+e.getMessage());
}
}
}
private void btnbatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kosongkan();
}
// TODO add your handling code here:
kosongkan();
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(1);
}
// TODO add your handling code here:
System.exit(1);
}
6. Untuk memunculkan keterangan tabelnya, kita lakukan berikut ini
7. Masukkan Kodingannya sebagai berikut
private void gridpengirimMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
txtno.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),1)));
txtnama.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),2)));
txtalamat.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),3)));
txtkota.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),4)));
txtprovinsi.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),5)));
txtkodepos.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),6)));
txtdaerah.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),7)));
txttelepon.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),8)));
// TODO add your handling code here:
txtno.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),1)));
txtnama.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),2)));
txtalamat.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),3)));
txtkota.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),4)));
txtprovinsi.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),5)));
txtkodepos.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),6)));
txtdaerah.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),7)));
txttelepon.setText(String.valueOf(gridpengirim.getValueAt(gridpengirim.getSelectedRow(),8)));
}
FORM PENGIRIMAN BARANG
1. Buat JFrame "Form_Pengirim", kita akan buat formnya seperti ini
2. Maka kita buat variabelnya seperti berikut
- Label1 = No. Resi
- Label2 = Tanggal
- Label3 = ID Petugas
- Label4 = Nama Petugas
- Label5 = Jabatan
- Label6 = Paket Type
- Label7 = Biaya
- Label8 = Asuransi
- Label9 = Berat
- Label10 = Total
- Label11 = No. Pengirim
- Label12 = Nama
- Label13 = Penerima
- Label14 = Kota Tujuan
- Label15 = Telepon
- TextArea1 = Alamat
- TextArea2 = Isi Paket
- TextArea3 = Alamat
- TextField = txtresi
- TextField2 = txttanggal
- TextField3 = txtnamapetugas
- TextField4 = txtjabatan
- TextField5 = txtbiaya
- TextField6 = txtasuransi
- TextField7 = txtberat
- TextField8 = txttotal
- TextField7 = txtnama
- TextField7 = txtpenerima
- TextField7 = txtkotatujuan
- TextField7 = txttelepon
- jButton1 = Simpan
- jButton2 = Ubah
- jButton3 = Hapus
- jButton4 = Batal
- jButton5 = Keluar
- Tabel1 = gridpengiriman
3. Untuk menghubungkan database (tb_pengiriman_barang) maka kita masukkan kodingannya di line 6
package Form_Pengiriman_Barang;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Pengiriman_Barang extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rskirim;
private ResultSet rspetugas;
private ResultSet rspaket;
private ResultSet rspengirim;
private String sql="";
private String resi,tanggal,tujuan,idpetugas,nopengirim,penerima,alamat,telepon,pakettype,isipaket;
private int berat,biaya,asuransi,total;
/**
* Creates new form Form_Pengiriman_Barang
*/
public Form_Pengiriman_Barang() {
initComponents();
koneksikan();
daftarpetugas();
daftarpengirim();
daftarpaket();
tampildata("select * from tb_pengiriman_barang");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Rizqy Syahputra
*/
public class Form_Pengiriman_Barang extends javax.swing.JFrame {
private Connection con;
private Statement st;
private ResultSet rskirim;
private ResultSet rspetugas;
private ResultSet rspaket;
private ResultSet rspengirim;
private String sql="";
private String resi,tanggal,tujuan,idpetugas,nopengirim,penerima,alamat,telepon,pakettype,isipaket;
private int berat,biaya,asuransi,total;
/**
* Creates new form Form_Pengiriman_Barang
*/
public Form_Pengiriman_Barang() {
initComponents();
koneksikan();
daftarpetugas();
daftarpengirim();
daftarpaket();
tampildata("select * from tb_pengiriman_barang");
}
private void koneksikan() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pengiriman_barang","root","");
System.out.println("Koneksi berhasil");
JOptionPane.showMessageDialog(null, "koneksi berhasil");
} catch (Exception e) {
System.out.println("Koneksi Gagal \n"+e);
}
}
private void tampildata(String sql) {
DefaultTableModel datalist = new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("NO Resi");
datalist.addColumn("Tanggal");
datalist.addColumn("Tujuan");
datalist.addColumn("ID Petugas");
datalist.addColumn("NO Pengirim");
datalist.addColumn("Penerima");
datalist.addColumn("Alamat");
datalist.addColumn("Telepon");
datalist.addColumn("Paket");
datalist.addColumn("Berat");
datalist.addColumn("Biaya");
datalist.addColumn("Asuransi");
datalist.addColumn("Isi Paket");
datalist.addColumn("Total");
try {
int i = 1;
st=con.createStatement();
rskirim=st.executeQuery("select * from tb_pengiriman_barang");
while (rskirim.next()) {
datalist.addRow(new Object[]{
(""+i++),rskirim.getString(1),
rskirim.getString(2),rskirim.getString(3),
rskirim.getString(4),
rskirim.getString(5),
rskirim.getString(6),
rskirim.getString(7),
rskirim.getString(8),
rskirim.getString(9),
rskirim.getString(10),
rskirim.getString(11),
rskirim.getString(12),
rskirim.getString(13),
rskirim.getString(14)
});
gridpengiriman.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void kosongkan(){
txtresi.setText("");
txttanggal.setText("");
txtkotatujuan.setText("");
txtidpetugas.setSelectedItem("-pilih-");
txtnopengirim.setSelectedItem("-pilih-");
txtpenerima.setText("");
txtalamatpenerima.setText("");
txttelepon.setText("");
txtpakettype.setSelectedItem("-pilih-");
txtberat.setText("");
txtbiaya.setText("");
txtasuransi.setText("");
txtisipaket.setText("");
txttotal.setText("");
}
DefaultTableModel datalist = new DefaultTableModel();
datalist.addColumn("No");
datalist.addColumn("NO Resi");
datalist.addColumn("Tanggal");
datalist.addColumn("Tujuan");
datalist.addColumn("ID Petugas");
datalist.addColumn("NO Pengirim");
datalist.addColumn("Penerima");
datalist.addColumn("Alamat");
datalist.addColumn("Telepon");
datalist.addColumn("Paket");
datalist.addColumn("Berat");
datalist.addColumn("Biaya");
datalist.addColumn("Asuransi");
datalist.addColumn("Isi Paket");
datalist.addColumn("Total");
try {
int i = 1;
st=con.createStatement();
rskirim=st.executeQuery("select * from tb_pengiriman_barang");
while (rskirim.next()) {
datalist.addRow(new Object[]{
(""+i++),rskirim.getString(1),
rskirim.getString(2),rskirim.getString(3),
rskirim.getString(4),
rskirim.getString(5),
rskirim.getString(6),
rskirim.getString(7),
rskirim.getString(8),
rskirim.getString(9),
rskirim.getString(10),
rskirim.getString(11),
rskirim.getString(12),
rskirim.getString(13),
rskirim.getString(14)
});
gridpengiriman.setModel(datalist);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void kosongkan(){
txtresi.setText("");
txttanggal.setText("");
txtkotatujuan.setText("");
txtidpetugas.setSelectedItem("-pilih-");
txtnopengirim.setSelectedItem("-pilih-");
txtpenerima.setText("");
txtalamatpenerima.setText("");
txttelepon.setText("");
txtpakettype.setSelectedItem("-pilih-");
txtberat.setText("");
txtbiaya.setText("");
txtasuransi.setText("");
txtisipaket.setText("");
txttotal.setText("");
}
4. Kemudian kita langsung kerjakan jButton "Simpan,Ubah,Hapus,Batal,Keluar" dengan actionPerformed
5. Lalu kita mulai masukkan kodingannya seperti berikut
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
private void txtsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int by,br,tot;
String hasil;
by=Integer.parseInt(txtbiaya.getText());
br=Integer.parseInt(txtberat.getText());
tot=by*br;
hasil=String.valueOf(tot);
txttotal.setText(hasil);
resi=String.valueOf(txtresi.getText());
tanggal=String.valueOf(txttanggal.getText());
tujuan=String.valueOf(txtkotatujuan.getText());
idpetugas=txtidpetugas.getItemAt(txtidpetugas.getSelectedIndex()).toString();
nopengirim=txtnopengirim.getItemAt(txtnopengirim.getSelectedIndex()).toString();
penerima=String.valueOf(txtpenerima.getText());
alamat=String.valueOf(txtalamatpenerima.getText());
telepon=String.valueOf(txttelepon.getText());
pakettype=txtpakettype.getItemAt(txtpakettype.getSelectedIndex()).toString();
berat=Integer.parseInt(txtberat.getText());
biaya=Integer.parseInt(txtbiaya.getText());
asuransi=Integer.parseInt(txtasuransi.getText());
isipaket=String.valueOf(txtisipaket.getText());
total=Integer.parseInt(txttotal.getText());
try {
sql = "insert into tb_pengiriman_barang(no_resi,tanggal,kota_tujuan,id_petugas,no_pengirim,penerima,alamat,telepon,paket_type,berat,biaya,asuransi,isi_paket,total)value ("
+ "'"+ resi +"','"+ tanggal +"','"+ tujuan +"','"+ idpetugas +"','"+ nopengirim +"','"+ penerima +"','"+ alamat +"','"+ telepon +"','"+ pakettype +"','"+ berat +"','"+ biaya +"','"+ asuransi +"','"+ isipaket +"','"+ total + "')";
st=con.createStatement();
st.execute(sql);
tampildata("select * tb_pengiriman_barang");
JOptionPane.showMessageDialog(null, "Data Berhasil Disimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "data gagal disimmpan \n"+e.getMessage());
}
kosongkan();
}
private void txtsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int by,br,tot;
String hasil;
by=Integer.parseInt(txtbiaya.getText());
br=Integer.parseInt(txtberat.getText());
tot=by*br;
hasil=String.valueOf(tot);
txttotal.setText(hasil);
resi=String.valueOf(txtresi.getText());
tanggal=String.valueOf(txttanggal.getText());
tujuan=String.valueOf(txtkotatujuan.getText());
idpetugas=txtidpetugas.getItemAt(txtidpetugas.getSelectedIndex()).toString();
nopengirim=txtnopengirim.getItemAt(txtnopengirim.getSelectedIndex()).toString();
penerima=String.valueOf(txtpenerima.getText());
alamat=String.valueOf(txtalamatpenerima.getText());
telepon=String.valueOf(txttelepon.getText());
pakettype=txtpakettype.getItemAt(txtpakettype.getSelectedIndex()).toString();
berat=Integer.parseInt(txtberat.getText());
biaya=Integer.parseInt(txtbiaya.getText());
asuransi=Integer.parseInt(txtasuransi.getText());
isipaket=String.valueOf(txtisipaket.getText());
total=Integer.parseInt(txttotal.getText());
try {
sql = "insert into tb_pengiriman_barang(no_resi,tanggal,kota_tujuan,id_petugas,no_pengirim,penerima,alamat,telepon,paket_type,berat,biaya,asuransi,isi_paket,total)value ("
+ "'"+ resi +"','"+ tanggal +"','"+ tujuan +"','"+ idpetugas +"','"+ nopengirim +"','"+ penerima +"','"+ alamat +"','"+ telepon +"','"+ pakettype +"','"+ berat +"','"+ biaya +"','"+ asuransi +"','"+ isipaket +"','"+ total + "')";
st=con.createStatement();
st.execute(sql);
tampildata("select * tb_pengiriman_barang");
JOptionPane.showMessageDialog(null, "Data Berhasil Disimpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "data gagal disimmpan \n"+e.getMessage());
}
kosongkan();
}
private void btnubahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
resi=String.valueOf(txtresi.getText());
tanggal=String.valueOf(txttanggal.getText());
tujuan=String.valueOf(txtkotatujuan.getText());
idpetugas=txtidpetugas.getItemAt(txtidpetugas.getSelectedIndex()).toString();
nopengirim=txtnopengirim.getItemAt(txtnopengirim.getSelectedIndex()).toString();
penerima=String.valueOf(txtpenerima.getText());
alamat=String.valueOf(txtalamatpenerima.getText());
telepon=String.valueOf(txttelepon.getText());
pakettype=txtpakettype.getItemAt(txtpakettype.getSelectedIndex()).toString();
berat=Integer.parseInt(txtberat.getText());
biaya=Integer.parseInt(txtbiaya.getText());
asuransi=Integer.parseInt(txtasuransi.getText());
isipaket=String.valueOf(txtisipaket.getText());
total=Integer.parseInt(txttotal.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah data ini mau diubah","konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION) {
try {
sql = "update tb_pengiriman_barang set kota_tujuan ='"+ tujuan +"' ,id_petugas='"+ idpetugas +"',"
+ "no_pengirim='"+ nopengirim +"',penerima= '"+ penerima +"',"
+ "alamat='"+ alamat +"',telepon='"+ telepon +"',paket_type='"+ pakettype +"',"
+ "berat='"+ berat +"',biaya='"+ biaya +"',asuransi='"+ asuransi +"',isi_paket='"+ isipaket +"',"
+ "total='"+ total +"' where no_resi='"+ resi +"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * tb_pengiriman_barang");
JOptionPane.showMessageDialog(null, "Data Berhasil Dirubah");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "data gagal dirubah \n"+e.getMessage());
}
}
}
// TODO add your handling code here:
resi=String.valueOf(txtresi.getText());
tanggal=String.valueOf(txttanggal.getText());
tujuan=String.valueOf(txtkotatujuan.getText());
idpetugas=txtidpetugas.getItemAt(txtidpetugas.getSelectedIndex()).toString();
nopengirim=txtnopengirim.getItemAt(txtnopengirim.getSelectedIndex()).toString();
penerima=String.valueOf(txtpenerima.getText());
alamat=String.valueOf(txtalamatpenerima.getText());
telepon=String.valueOf(txttelepon.getText());
pakettype=txtpakettype.getItemAt(txtpakettype.getSelectedIndex()).toString();
berat=Integer.parseInt(txtberat.getText());
biaya=Integer.parseInt(txtbiaya.getText());
asuransi=Integer.parseInt(txtasuransi.getText());
isipaket=String.valueOf(txtisipaket.getText());
total=Integer.parseInt(txttotal.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah data ini mau diubah","konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION) {
try {
sql = "update tb_pengiriman_barang set kota_tujuan ='"+ tujuan +"' ,id_petugas='"+ idpetugas +"',"
+ "no_pengirim='"+ nopengirim +"',penerima= '"+ penerima +"',"
+ "alamat='"+ alamat +"',telepon='"+ telepon +"',paket_type='"+ pakettype +"',"
+ "berat='"+ berat +"',biaya='"+ biaya +"',asuransi='"+ asuransi +"',isi_paket='"+ isipaket +"',"
+ "total='"+ total +"' where no_resi='"+ resi +"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * tb_pengiriman_barang");
JOptionPane.showMessageDialog(null, "Data Berhasil Dirubah");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "data gagal dirubah \n"+e.getMessage());
}
}
}
private void btnbatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kosongkan();
}
// TODO add your handling code here:
kosongkan();
}
private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
resi=String.valueOf(txtresi.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah anda yakin menghapus data ini","Konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION)
{
try {
sql="delete from tb_pengiriman_barang where no_resi='"+resi+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengiriman_barang");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal di hapus\n"+e.getMessage());
}
}
}
// TODO add your handling code here:
resi=String.valueOf(txtresi.getText());
if (JOptionPane.showConfirmDialog(this,"Apakah anda yakin menghapus data ini","Konfirmasi",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==
JOptionPane.YES_OPTION)
{
try {
sql="delete from tb_pengiriman_barang where no_resi='"+resi+"'";
st=con.createStatement();
st.execute(sql);
tampildata("select * from tb_pengiriman_barang");
kosongkan();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"data gagal di hapus\n"+e.getMessage());
}
}
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(1);
}
// TODO add your handling code here:
System.exit(1);
}
6. Untuk memunculkan keterangan tabelnya, kita lakukan berikut ini
7. Masukkan Kodingannya sebagai berikut
private void gridpengirimanMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
txtresi.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),1)));
txttanggal.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),2)));
txtkotatujuan.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),3)));
txtidpetugas.setSelectedItem(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),4)));
txtnopengirim.setSelectedItem(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),5)));
txtpenerima.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),6)));
txtalamatpenerima.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),7)));
txttelepon.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),8)));
txtpakettype.setSelectedItem(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),9)));
txtberat.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),10)));
txtbiaya.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),11)));
txtasuransi.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),12)));
txtisipaket.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),13)));
txttotal.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),14)));
}
// TODO add your handling code here:
txtresi.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),1)));
txttanggal.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),2)));
txtkotatujuan.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),3)));
txtidpetugas.setSelectedItem(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),4)));
txtnopengirim.setSelectedItem(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),5)));
txtpenerima.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),6)));
txtalamatpenerima.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),7)));
txttelepon.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),8)));
txtpakettype.setSelectedItem(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),9)));
txtberat.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),10)));
txtbiaya.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),11)));
txtasuransi.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),12)));
txtisipaket.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),13)));
txttotal.setText(String.valueOf(gridpengiriman.getValueAt(gridpengiriman.getSelectedRow(),14)));
}
8. Agar ComboBoxnya (ID Petugas, Jenis Paket dan No. Pengirim) terhubung dengan form (jenis_paket, pengirim dan petugas) maka kita lakukan hal berikut ini
9. Masukkan Kodingannya
private void txtnopengirimItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
try {
sql="select * from tb_pengirim where "
+ "no_pengirim='" +txtnopengirim.getSelectedItem()+ "'";
st=con.createStatement();
rspengirim=st.executeQuery(sql);
while (rspengirim.next()) {
txtnamapengirim.setText(rspengirim.getString(2));
txtalamatpengirim.setText(rspengirim.getString(3));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
// TODO add your handling code here:
try {
sql="select * from tb_pengirim where "
+ "no_pengirim='" +txtnopengirim.getSelectedItem()+ "'";
st=con.createStatement();
rspengirim=st.executeQuery(sql);
while (rspengirim.next()) {
txtnamapengirim.setText(rspengirim.getString(2));
txtalamatpengirim.setText(rspengirim.getString(3));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void daftarpengirim(){
txtnopengirim.removeAllItems();
txtnopengirim.addItem("Pilih");
try {
String sql ="select * from tb_pengirim";
Statement st=con.createStatement();
rspengirim=st.executeQuery(sql);
while(rspengirim.next()) {
String aliasid=rspengirim.getString("no_pengirim");
txtnopengirim.addItem(aliasid);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void txtpakettypeItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
try {
sql="select * from tb_jenis_paket where "
+ "paket_type='" +txtpakettype.getSelectedItem()+ "'";
st=con.createStatement();
rspaket=st.executeQuery(sql);
while (rspaket.next()) {
txtbiaya.setText(rspaket.getString(4));
txtasuransi.setText(rspaket.getString(3));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
txtnopengirim.removeAllItems();
txtnopengirim.addItem("Pilih");
try {
String sql ="select * from tb_pengirim";
Statement st=con.createStatement();
rspengirim=st.executeQuery(sql);
while(rspengirim.next()) {
String aliasid=rspengirim.getString("no_pengirim");
txtnopengirim.addItem(aliasid);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void txtpakettypeItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
try {
sql="select * from tb_jenis_paket where "
+ "paket_type='" +txtpakettype.getSelectedItem()+ "'";
st=con.createStatement();
rspaket=st.executeQuery(sql);
while (rspaket.next()) {
txtbiaya.setText(rspaket.getString(4));
txtasuransi.setText(rspaket.getString(3));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
private void daftarpaket(){
txtpakettype.removeAllItems();
txtpakettype.addItem("Pilih");
try {
String sql ="select * from tb_jenis_paket";
Statement st=con.createStatement();
rspaket=st.executeQuery(sql);
while (rspaket.next()) {
String aliasid=rspaket.getString("paket_type");
txtpakettype.addItem(aliasid);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
txtpakettype.removeAllItems();
txtpakettype.addItem("Pilih");
try {
String sql ="select * from tb_jenis_paket";
Statement st=con.createStatement();
rspaket=st.executeQuery(sql);
while (rspaket.next()) {
String aliasid=rspaket.getString("paket_type");
txtpakettype.addItem(aliasid);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Gagal Tampil \n"+e.getMessage());
}
}
Demikian hasil kodingan Aplikasi Pengiriman Barang, semoga program ini bisa bermanfaat dan dipergunakan sebaik mungkin. Kurang lebihnya mohon maaf serta apabila ada kata kata yang kurang berkenan. Atas perhatiannya saya ucapkan Terima Kasih.
makasi tutornya bermanfaat skali.
BalasHapusdatabase nya kalau di buat di mysql phpmyadmin sama aja atw gak?
MANTAP
BalasHapusMantappp
BalasHapus