aplikasi kopi dengan report wizard
Pada postingan blog lanjutan ini, saya akan
memposting tentang membuat aplikasi sederhana menggunakan Java Netbeans dengan Report Wizard,
aplikasi yang dibuat adalah aplikasi penjualan kopi, dimana aplikasi ini di
buat untuk mempermudah para penikmat kopi mendapatkan kopi favoritenya dengan
mudah, dan membantu penjualan kopi di tempat itu sendiri.
Oke, untuk permulaan saya akan menampilkan flowchart terlebih dahulu, berikut flowchartnya
Berikut adalah penjelasan aplikasi sederhana yang
saya buat menggunakan Java Netbeans. saya membuat aplikasi penjualan kopi yang
diawali dengan mebuat form login terlebih dahuluOke, untuk permulaan saya akan menampilkan flowchart terlebih dahulu, berikut flowchartnya
Berikut adalah penjelasan aplikasi sederhana yang saya buat menggunakan Java Netbeans. saya membuat aplikasi penjualan kopi yang diawali dengan mebuat form login terlebih dahulu
Untuk
membuat desain login saya membutukan :
1. 4 JLabel
2. 1
Jtextfield
3. 1
JPasswordfield
4. 2 JButton
Berikut adalah source code yang saya gunakan untuk form
login
new pembayaran untuk memanggil data menu selanjutnya, saat
login berhasil maka akan masuk ke menu selanjutnya.
Setelah berhasil Login maka akan muncul menu seperti dibawah ini
Untuk membuat desain menu saya
membutukan ;
1. 8 Jtextfield
2. 3 Jradiobutton
3. 1 Jcheckbox
4. 7 Jlabel
5. 5 Jbutton
Ditempatkan dan diatur sedemikian rupa hingga menjadi seperti gambar diatas.
Untuk tombol Combo box "Kopi" saat di klik akan muncul seperti gambar di bawah ini
berikut source kodenya, agar bisa menjadi seperti gambar diatas
langkah selanjutnya adalah proses penghitungan bayar dan diskon
untuk mengetahui jumlah yang harus kita bayar, kita harus memasukan qty
secara manual, dan untuk mengetahui mendapat diskon atau tidak, kita
tinggal klik Checkbox nya, jika mendapat diskon akan muncul di textfield
potongan harga, dan berkut adalah source codenya:
setelah itu ada pilihan paket, yaitu paket1, paket2, dan paket3, dimana
dalam paket itu di bedakan harganya menjadi lebih murah, dan dengan qty
diatas 5, pemilihan paket ini dimaksudkan untuk pemesanan dalam jumlah
besar, dalam pemilihan paket ini tidak perlu memasukan qty karena sudah
diatur di dalam paket tersebut
untuk bisa seperti itu, berikut source code nya
tombol button bersih untuk membersihkan semua text, saat kita malas
menghapus manual, maka kita hanya harus menekan tombol bersih, maka
semua text akan hilang seperti saat tampilan awal, seperti gambar
dibawah ini
selanjutnya saat kita menekan tombol keluar
maka akan muncul warning message atau pertanyaan apakah "anda yakin
selesai" seperti gambar dibawah ini
untuk source kodenya saya menggunakan JOptionpane seperti gambar dibawah ini:
umtuk buton simpan, digunakan untuk proses penyimpan ke database, semua pesanan akan tersimpan di database sesuai dengan apa yang dipesan, jangan lupa untuk menkoneksikannya ke database terlebih dahulu, sudah terkonek ke database jika di localhost sudah tersimpan seperti ini;
selanjutnya adalah buton cetak, buton cetak untuk menampilkan report wizard seperti gambar dibawah ini :
untuk bisa menampilkan seperti gambar diatas, maka kita perlu membuat report nya terlebih dahulu, dibawah ini saya akan menjelaskan cara pembuatannya
pertama kita buat project baru di neatbens, dan buat file
report seperti gambar dibawah ini:
lalu akan muncul tampilan seperti dibawah ini:
Pilih layout kemudian klik next
Lalu akan muncul gambar seperti
dibawah
Isi semua sesuai dengan data
anda, seperti yang terlihat pada gambar diatas
Lalu klik next
lalu akan muncul tampilan seperti dibawah ini
Pilih sesuai data anda di mysql
Lalu klik ok
selanjutnya klik next
Klik tombol >> maka akan
menjadi seperti pada gambar diatas
Lalu klik next
Isi sesuai keinginan anda, tapi
saya menyarankan isi group 1 saja
Selanjutnya klik next
Jika sudah seperti gambar diatas,
maka anda sudah berhasil membuat report wizard, dan klik finish
Dan
jika ingin mengedit, kita aktifkan tombol designernya, dan untuk menambah
tulisan atau semacamnya, anda hanya perlu mengklik lalu menggesernya saja, ini sudah bisa diaplikasikan di netbeans anda.
Berikut sedikit video tutorial nya dalam penjalanan aplikasi ini:
dan ini adalah semua source code nya:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nusantarakopi;
import javax.swing.JOptionPane;
import java.awt.event.*;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import javax.swing.JOptionPane;
/**
*
* @author Deny
*/
public class pembayaran extends javax.swing.JFrame {
Connection koneksi;
private Object kopi;
/**
* Creates new form pembayaran
*/
public pembayaran() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtharga = new javax.swing.JTextField();
txtqty = new javax.swing.JTextField();
txtpot = new javax.swing.JTextField();
btnhitung = new javax.swing.JButton();
txttotal = new javax.swing.JTextField();
txtnakop = new javax.swing.JTextField();
btnkeluar = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jpotongan = new javax.swing.JCheckBox();
jLabel4 = new javax.swing.JLabel();
btnbersih = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
txtnet = new javax.swing.JTextField();
jnakop = new javax.swing.JComboBox<>();
jjekop = new javax.swing.JLabel();
txtjekop = new javax.swing.JTextField();
rpkt3 = new javax.swing.JRadioButton();
rpkt2 = new javax.swing.JRadioButton();
rpkt1 = new javax.swing.JRadioButton();
btnsimpan = new javax.swing.JButton();
Btncetak = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
txttotal2 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jPanel1.setForeground(new java.awt.Color(255, 255, 255));
jPanel1.setLayout(null);
jLabel1.setBackground(new java.awt.Color(204, 204, 204));
jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(240, 240, 240));
jLabel1.setText("NUSANTARA KOPI");
jLabel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(204, 204, 204), new java.awt.Color(204, 204, 204), new java.awt.Color(204, 204, 204), new java.awt.Color(204, 204, 204)));
jPanel1.add(jLabel1);
jLabel1.setBounds(180, 10, 250, 40);
jPanel1.add(txtharga);
txtharga.setBounds(350, 110, 210, 30);
jPanel1.add(txtqty);
txtqty.setBounds(350, 140, 210, 30);
jPanel1.add(txtpot);
txtpot.setBounds(350, 170, 210, 30);
btnhitung.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnhitung.setText("Hitung");
btnhitung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhitungActionPerformed(evt);
}
});
jPanel1.add(btnhitung);
btnhitung.setBounds(230, 220, 120, 23);
jPanel1.add(txttotal);
txttotal.setBounds(350, 260, 210, 30);
txtnakop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtnakopActionPerformed(evt);
}
});
jPanel1.add(txtnakop);
txtnakop.setBounds(350, 50, 210, 30);
btnkeluar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
jPanel1.add(btnkeluar);
btnkeluar.setBounds(460, 330, 120, 23);
jLabel6.setBackground(new java.awt.Color(255, 255, 255));
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Bayar");
jLabel6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel6);
jLabel6.setBounds(40, 270, 110, 21);
jpotongan.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jpotongan.setText("Potongan Harga");
jpotongan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jpotonganActionPerformed(evt);
}
});
jPanel1.add(jpotongan);
jpotongan.setBounds(30, 180, 160, 23);
jLabel4.setBackground(new java.awt.Color(255, 255, 255));
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Harga");
jLabel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel4);
jLabel4.setBounds(40, 120, 90, 21);
btnbersih.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnbersih.setText("Bersih");
btnbersih.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnbersihActionPerformed(evt);
}
});
jPanel1.add(btnbersih);
btnbersih.setBounds(50, 330, 120, 23);
jLabel5.setBackground(new java.awt.Color(255, 255, 255));
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("Qty/Kg");
jLabel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel5);
jLabel5.setBounds(40, 150, 80, 21);
jLabel7.setBackground(new java.awt.Color(255, 255, 255));
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("Total Bayar");
jLabel7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel7);
jLabel7.setBounds(40, 300, 110, 21);
jPanel1.add(txtnet);
txtnet.setBounds(350, 290, 210, 30);
jnakop.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jnakop.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Kopi", "Gayo", "Kintamani", "Bajawa", "Lintong" }));
jnakop.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jnakopItemStateChanged(evt);
}
});
jnakop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jnakopActionPerformed(evt);
}
});
jPanel1.add(jnakop);
jnakop.setBounds(30, 60, 130, 21);
jjekop.setBackground(new java.awt.Color(153, 153, 153));
jjekop.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jjekop.setForeground(new java.awt.Color(255, 255, 255));
jjekop.setText("Jenis Kopi");
jjekop.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jjekop);
jjekop.setBounds(40, 90, 90, 21);
jPanel1.add(txtjekop);
txtjekop.setBounds(350, 80, 210, 30);
rpkt3.setBackground(new java.awt.Color(153, 153, 153));
rpkt3.setForeground(new java.awt.Color(255, 255, 255));
rpkt3.setText("Paket 3");
rpkt3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rpkt3ActionPerformed(evt);
}
});
jPanel1.add(rpkt3);
rpkt3.setBounds(580, 110, 80, 23);
rpkt2.setBackground(new java.awt.Color(153, 153, 153));
rpkt2.setForeground(new java.awt.Color(255, 255, 255));
rpkt2.setText("Paket 2");
rpkt2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rpkt2ActionPerformed(evt);
}
});
jPanel1.add(rpkt2);
rpkt2.setBounds(580, 80, 80, 23);
rpkt1.setBackground(new java.awt.Color(153, 153, 153));
rpkt1.setForeground(new java.awt.Color(255, 255, 255));
rpkt1.setText("Paket 1");
rpkt1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rpkt1ActionPerformed(evt);
}
});
jPanel1.add(rpkt1);
rpkt1.setBounds(580, 50, 80, 23);
btnsimpan.setText("Simpan");
btnsimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsimpanActionPerformed(evt);
}
});
jPanel1.add(btnsimpan);
btnsimpan.setBounds(250, 330, 80, 23);
Btncetak.setText("Cetak");
Btncetak.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtncetakActionPerformed(evt);
}
});
jPanel1.add(Btncetak);
Btncetak.setBounds(580, 220, 61, 23);
jLabel3.setIcon(new javax.swing.ImageIcon("C:\\Users\\FUJITSU\\Desktop\\bkf.jpg")); // NOI18N
jLabel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel3);
jLabel3.setBounds(0, 0, 700, 360);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel8.setText("Total Bayar");
jPanel1.add(jLabel8);
jLabel8.setBounds(40, 300, 110, 15);
jPanel1.add(txttotal2);
txttotal2.setBounds(360, 290, 210, 30);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
public void buka_db() {
try {
Class.forName("com.mysql.jdbc.Driver");
koneksi = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/dbkopikopi", "root", "");
} catch (ClassNotFoundException e) {
System.out.println("Error #1 " + e.getMessage());
System.exit(0);
} catch (SQLException e) {
System.out.println("Error #2 : " + e.getMessage());
System.exit(0);
}
}
private void txtnakopActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
buka_db();
}
private void btnhitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int Harga=Integer.parseInt(txtharga.getText());
int Jumlah=Integer.parseInt(txtqty.getText());
int Total=Harga*Jumlah;
txttotal.setText(""+Total);
}
private void jpotonganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double Total=Double.parseDouble(txttotal.getText());
if (jpotongan.isSelected()){
if(Total>=500000){
Double Potongan=Total*0.3;
Double net=Total-Potongan;
txtpot.setText(""+Potongan);
txtnet.setText(""+net);
}else if(Total>=250000){
Double Potongan=Total*0.2;
Double net=Total-Potongan;
txtpot.setText(""+Potongan);
txtnet.setText(""+net);
}else if(Total>=150000){
Double Potongan=Total*0.1;
Double net=Total-Potongan;
txtpot.setText(""+Potongan);
txtnet.setText(""+net);
}else {
txtpot.setText(""+0);
}
}else {
txtpot.setText(""+0);
}
}
private void btnbersihActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtharga.setText("");
txtjekop.setText("");
txtnakop.setText("");
txtnet.setText("");
txtpot.setText("");
txtqty.setText("");
txttotal.setText("");
txttotal2.setText("");
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (JOptionPane.showConfirmDialog(null,"Selesai","yakin",
JOptionPane.YES_NO_OPTION)
==JOptionPane.YES_OPTION){
dispose();
}
}
private void jnakopItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
if (jnakop.getSelectedItem().equals("Gayo")){
txtnakop.setText("Gayo");
txtjekop.setText("Arabika");
txtharga.setText("50000");
} else if (jnakop.getSelectedItem().equals("Kintamani")){
txtnakop.setText("Kintamani");
txtjekop.setText("Robusta");
txtharga.setText("45000");
}else if (jnakop.getSelectedItem().equals("Bajawa")){
txtnakop.setText("Bajawa");
txtjekop.setText("Robusta");
txtharga.setText("40000");
}else if (jnakop.getSelectedItem().equals("Lintong")){
txtnakop.setText("Lintong");
txtjekop.setText("Arabika");
txtharga.setText("40000");
}else {
txtnakop.setText("");
}
}
private void jnakopActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void rpkt1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
rpkt2.setSelected(false);
rpkt3.setSelected(false);
txtharga.setText("30000");
txtqty.setText("5");
txtjekop.setText("Arabika");
txtnakop.setText("Gayo");
}
private void rpkt2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
rpkt3.setSelected(false);
rpkt1.setSelected(false);
txtharga.setText("30000");
txtqty.setText("10");
txtjekop.setText("Arabika");
txtnakop.setText("Lintong");
}
private void rpkt3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
rpkt1.setSelected(false);
rpkt2.setSelected(false);
txtharga.setText("30000");
txtqty.setText("15");
txtjekop.setText("Arabika");
txtnakop.setText("Bajawa");
}
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
buka_db();
try{
String host = "jdbc:mysql://localhost:3306/dbkopikopi",
user ="root",
pass ="";
Connection con = (Connection) DriverManager.getConnection(host, user, pass);
String Kopi =txtnakop.getText();
String JenisKopi=txtjekop.getText();
int Harga=Integer.parseInt(txtharga.getText());
int Qty=Integer.parseInt (txtqty.getText());
Double PotonganHarga=Double.parseDouble(txtpot.getText());
int Bayar=Integer.parseInt(txttotal.getText());
Double TotalBayar=Double.parseDouble(txtnet.getText());
Statement st=con.createStatement();
st.executeUpdate("INSERT INTO tblkopi ( Kopi , JenisKopi , Harga , Qty , PotonganHarga , Bayar , TotalBayar )"
+ " VALUES ( '"+Kopi+"' , '"+JenisKopi+"' ,'"+Harga+"' , '"+Qty+"' , '"+PotonganHarga+"' , '"+Bayar+"' , '"+TotalBayar+"') ");
st.close();
JOptionPane.showMessageDialog(null,"Berhasil");
} catch (SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void BtncetakActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
buka_db();
try {
koneksi.createStatement();
Map<String, Object> maps = new HashMap<String, Object>();
JasperReport JRP = JasperCompileManager.compileReport("src/nusantarakopi/kopiku.jrxml");
JasperPrint JFILL = JasperFillManager.fillReport(JRP, maps, koneksi);
JasperViewer.viewReport(JFILL, false);
} catch (Exception rptexcpt) {
JOptionPane.showMessageDialog(null, "Salah Report");
System.out.println(rptexcpt);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new pembayaran().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Btncetak;
private javax.swing.JButton btnbersih;
private javax.swing.JButton btnhitung;
private javax.swing.JButton btnkeluar;
private javax.swing.JButton btnsimpan;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel jjekop;
private javax.swing.JComboBox<String> jnakop;
private javax.swing.JCheckBox jpotongan;
private javax.swing.JRadioButton rpkt1;
private javax.swing.JRadioButton rpkt2;
private javax.swing.JRadioButton rpkt3;
private javax.swing.JTextField txtharga;
private javax.swing.JTextField txtjekop;
private javax.swing.JTextField txtnakop;
private javax.swing.JTextField txtnet;
private javax.swing.JTextField txtpot;
private javax.swing.JTextField txtqty;
private javax.swing.JTextField txttotal;
private javax.swing.JTextField txttotal2;
// End of variables declaration
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nusantarakopi;
import javax.swing.JOptionPane;
import java.awt.event.*;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import javax.swing.JOptionPane;
/**
*
* @author Deny
*/
public class pembayaran extends javax.swing.JFrame {
Connection koneksi;
private Object kopi;
/**
* Creates new form pembayaran
*/
public pembayaran() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtharga = new javax.swing.JTextField();
txtqty = new javax.swing.JTextField();
txtpot = new javax.swing.JTextField();
btnhitung = new javax.swing.JButton();
txttotal = new javax.swing.JTextField();
txtnakop = new javax.swing.JTextField();
btnkeluar = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jpotongan = new javax.swing.JCheckBox();
jLabel4 = new javax.swing.JLabel();
btnbersih = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
txtnet = new javax.swing.JTextField();
jnakop = new javax.swing.JComboBox<>();
jjekop = new javax.swing.JLabel();
txtjekop = new javax.swing.JTextField();
rpkt3 = new javax.swing.JRadioButton();
rpkt2 = new javax.swing.JRadioButton();
rpkt1 = new javax.swing.JRadioButton();
btnsimpan = new javax.swing.JButton();
Btncetak = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
txttotal2 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jPanel1.setForeground(new java.awt.Color(255, 255, 255));
jPanel1.setLayout(null);
jLabel1.setBackground(new java.awt.Color(204, 204, 204));
jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(240, 240, 240));
jLabel1.setText("NUSANTARA KOPI");
jLabel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(204, 204, 204), new java.awt.Color(204, 204, 204), new java.awt.Color(204, 204, 204), new java.awt.Color(204, 204, 204)));
jPanel1.add(jLabel1);
jLabel1.setBounds(180, 10, 250, 40);
jPanel1.add(txtharga);
txtharga.setBounds(350, 110, 210, 30);
jPanel1.add(txtqty);
txtqty.setBounds(350, 140, 210, 30);
jPanel1.add(txtpot);
txtpot.setBounds(350, 170, 210, 30);
btnhitung.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnhitung.setText("Hitung");
btnhitung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhitungActionPerformed(evt);
}
});
jPanel1.add(btnhitung);
btnhitung.setBounds(230, 220, 120, 23);
jPanel1.add(txttotal);
txttotal.setBounds(350, 260, 210, 30);
txtnakop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtnakopActionPerformed(evt);
}
});
jPanel1.add(txtnakop);
txtnakop.setBounds(350, 50, 210, 30);
btnkeluar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
jPanel1.add(btnkeluar);
btnkeluar.setBounds(460, 330, 120, 23);
jLabel6.setBackground(new java.awt.Color(255, 255, 255));
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Bayar");
jLabel6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel6);
jLabel6.setBounds(40, 270, 110, 21);
jpotongan.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jpotongan.setText("Potongan Harga");
jpotongan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jpotonganActionPerformed(evt);
}
});
jPanel1.add(jpotongan);
jpotongan.setBounds(30, 180, 160, 23);
jLabel4.setBackground(new java.awt.Color(255, 255, 255));
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Harga");
jLabel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel4);
jLabel4.setBounds(40, 120, 90, 21);
btnbersih.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnbersih.setText("Bersih");
btnbersih.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnbersihActionPerformed(evt);
}
});
jPanel1.add(btnbersih);
btnbersih.setBounds(50, 330, 120, 23);
jLabel5.setBackground(new java.awt.Color(255, 255, 255));
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("Qty/Kg");
jLabel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel5);
jLabel5.setBounds(40, 150, 80, 21);
jLabel7.setBackground(new java.awt.Color(255, 255, 255));
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("Total Bayar");
jLabel7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel7);
jLabel7.setBounds(40, 300, 110, 21);
jPanel1.add(txtnet);
txtnet.setBounds(350, 290, 210, 30);
jnakop.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jnakop.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Kopi", "Gayo", "Kintamani", "Bajawa", "Lintong" }));
jnakop.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jnakopItemStateChanged(evt);
}
});
jnakop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jnakopActionPerformed(evt);
}
});
jPanel1.add(jnakop);
jnakop.setBounds(30, 60, 130, 21);
jjekop.setBackground(new java.awt.Color(153, 153, 153));
jjekop.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jjekop.setForeground(new java.awt.Color(255, 255, 255));
jjekop.setText("Jenis Kopi");
jjekop.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jjekop);
jjekop.setBounds(40, 90, 90, 21);
jPanel1.add(txtjekop);
txtjekop.setBounds(350, 80, 210, 30);
rpkt3.setBackground(new java.awt.Color(153, 153, 153));
rpkt3.setForeground(new java.awt.Color(255, 255, 255));
rpkt3.setText("Paket 3");
rpkt3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rpkt3ActionPerformed(evt);
}
});
jPanel1.add(rpkt3);
rpkt3.setBounds(580, 110, 80, 23);
rpkt2.setBackground(new java.awt.Color(153, 153, 153));
rpkt2.setForeground(new java.awt.Color(255, 255, 255));
rpkt2.setText("Paket 2");
rpkt2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rpkt2ActionPerformed(evt);
}
});
jPanel1.add(rpkt2);
rpkt2.setBounds(580, 80, 80, 23);
rpkt1.setBackground(new java.awt.Color(153, 153, 153));
rpkt1.setForeground(new java.awt.Color(255, 255, 255));
rpkt1.setText("Paket 1");
rpkt1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rpkt1ActionPerformed(evt);
}
});
jPanel1.add(rpkt1);
rpkt1.setBounds(580, 50, 80, 23);
btnsimpan.setText("Simpan");
btnsimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsimpanActionPerformed(evt);
}
});
jPanel1.add(btnsimpan);
btnsimpan.setBounds(250, 330, 80, 23);
Btncetak.setText("Cetak");
Btncetak.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtncetakActionPerformed(evt);
}
});
jPanel1.add(Btncetak);
Btncetak.setBounds(580, 220, 61, 23);
jLabel3.setIcon(new javax.swing.ImageIcon("C:\\Users\\FUJITSU\\Desktop\\bkf.jpg")); // NOI18N
jLabel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.add(jLabel3);
jLabel3.setBounds(0, 0, 700, 360);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel8.setText("Total Bayar");
jPanel1.add(jLabel8);
jLabel8.setBounds(40, 300, 110, 15);
jPanel1.add(txttotal2);
txttotal2.setBounds(360, 290, 210, 30);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
public void buka_db() {
try {
Class.forName("com.mysql.jdbc.Driver");
koneksi = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/dbkopikopi", "root", "");
} catch (ClassNotFoundException e) {
System.out.println("Error #1 " + e.getMessage());
System.exit(0);
} catch (SQLException e) {
System.out.println("Error #2 : " + e.getMessage());
System.exit(0);
}
}
private void txtnakopActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
buka_db();
}
private void btnhitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int Harga=Integer.parseInt(txtharga.getText());
int Jumlah=Integer.parseInt(txtqty.getText());
int Total=Harga*Jumlah;
txttotal.setText(""+Total);
}
private void jpotonganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double Total=Double.parseDouble(txttotal.getText());
if (jpotongan.isSelected()){
if(Total>=500000){
Double Potongan=Total*0.3;
Double net=Total-Potongan;
txtpot.setText(""+Potongan);
txtnet.setText(""+net);
}else if(Total>=250000){
Double Potongan=Total*0.2;
Double net=Total-Potongan;
txtpot.setText(""+Potongan);
txtnet.setText(""+net);
}else if(Total>=150000){
Double Potongan=Total*0.1;
Double net=Total-Potongan;
txtpot.setText(""+Potongan);
txtnet.setText(""+net);
}else {
txtpot.setText(""+0);
}
}else {
txtpot.setText(""+0);
}
}
private void btnbersihActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtharga.setText("");
txtjekop.setText("");
txtnakop.setText("");
txtnet.setText("");
txtpot.setText("");
txtqty.setText("");
txttotal.setText("");
txttotal2.setText("");
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (JOptionPane.showConfirmDialog(null,"Selesai","yakin",
JOptionPane.YES_NO_OPTION)
==JOptionPane.YES_OPTION){
dispose();
}
}
private void jnakopItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
if (jnakop.getSelectedItem().equals("Gayo")){
txtnakop.setText("Gayo");
txtjekop.setText("Arabika");
txtharga.setText("50000");
} else if (jnakop.getSelectedItem().equals("Kintamani")){
txtnakop.setText("Kintamani");
txtjekop.setText("Robusta");
txtharga.setText("45000");
}else if (jnakop.getSelectedItem().equals("Bajawa")){
txtnakop.setText("Bajawa");
txtjekop.setText("Robusta");
txtharga.setText("40000");
}else if (jnakop.getSelectedItem().equals("Lintong")){
txtnakop.setText("Lintong");
txtjekop.setText("Arabika");
txtharga.setText("40000");
}else {
txtnakop.setText("");
}
}
private void jnakopActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void rpkt1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
rpkt2.setSelected(false);
rpkt3.setSelected(false);
txtharga.setText("30000");
txtqty.setText("5");
txtjekop.setText("Arabika");
txtnakop.setText("Gayo");
}
private void rpkt2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
rpkt3.setSelected(false);
rpkt1.setSelected(false);
txtharga.setText("30000");
txtqty.setText("10");
txtjekop.setText("Arabika");
txtnakop.setText("Lintong");
}
private void rpkt3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
rpkt1.setSelected(false);
rpkt2.setSelected(false);
txtharga.setText("30000");
txtqty.setText("15");
txtjekop.setText("Arabika");
txtnakop.setText("Bajawa");
}
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
buka_db();
try{
String host = "jdbc:mysql://localhost:3306/dbkopikopi",
user ="root",
pass ="";
Connection con = (Connection) DriverManager.getConnection(host, user, pass);
String Kopi =txtnakop.getText();
String JenisKopi=txtjekop.getText();
int Harga=Integer.parseInt(txtharga.getText());
int Qty=Integer.parseInt (txtqty.getText());
Double PotonganHarga=Double.parseDouble(txtpot.getText());
int Bayar=Integer.parseInt(txttotal.getText());
Double TotalBayar=Double.parseDouble(txtnet.getText());
Statement st=con.createStatement();
st.executeUpdate("INSERT INTO tblkopi ( Kopi , JenisKopi , Harga , Qty , PotonganHarga , Bayar , TotalBayar )"
+ " VALUES ( '"+Kopi+"' , '"+JenisKopi+"' ,'"+Harga+"' , '"+Qty+"' , '"+PotonganHarga+"' , '"+Bayar+"' , '"+TotalBayar+"') ");
st.close();
JOptionPane.showMessageDialog(null,"Berhasil");
} catch (SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void BtncetakActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
buka_db();
try {
koneksi.createStatement();
Map<String, Object> maps = new HashMap<String, Object>();
JasperReport JRP = JasperCompileManager.compileReport("src/nusantarakopi/kopiku.jrxml");
JasperPrint JFILL = JasperFillManager.fillReport(JRP, maps, koneksi);
JasperViewer.viewReport(JFILL, false);
} catch (Exception rptexcpt) {
JOptionPane.showMessageDialog(null, "Salah Report");
System.out.println(rptexcpt);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new pembayaran().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Btncetak;
private javax.swing.JButton btnbersih;
private javax.swing.JButton btnhitung;
private javax.swing.JButton btnkeluar;
private javax.swing.JButton btnsimpan;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel jjekop;
private javax.swing.JComboBox<String> jnakop;
private javax.swing.JCheckBox jpotongan;
private javax.swing.JRadioButton rpkt1;
private javax.swing.JRadioButton rpkt2;
private javax.swing.JRadioButton rpkt3;
private javax.swing.JTextField txtharga;
private javax.swing.JTextField txtjekop;
private javax.swing.JTextField txtnakop;
private javax.swing.JTextField txtnet;
private javax.swing.JTextField txtpot;
private javax.swing.JTextField txtqty;
private javax.swing.JTextField txttotal;
private javax.swing.JTextField txttotal2;
// End of variables declaration
}
Demikian aplikasi sederhana yang saya buat, meskipun banyak sekali
kekurangan didalamnya, saya harap bisa bermanfaat untuk teman-teman yang
lain.
Sekian dan terimakasih
wasalamualaikum wr wb
Komentar
Posting Komentar