Pada Postingan blog kali ini saya akan memposting tentang membuat aplikasi sederhana mengunakan Java Netbeans dengan Report Wizard aplikasi yang di buat adalah aplikasi penjualan laptop,dimana aplikasi ini di gunakan untuk mempermudah para penjual laptop, dimana aplikasi ini dibuat untuk mempermudah para pembeli laptop mendapatkan laptop favorit dengan mudah dan membantu penjual laptop ditempat itu sendiri.
oke, untuk permulaan saya akan menampilkan flowchart terlebih dahulu,
Berikut contoh flowchart:
Berikut adalah penjelasan aplikasi sederhana yang saya buat dengan menggunakan Netbeans saya membuat aplikasi penjualan laptop dengan membuat from login terlebih dahulu
Untuk membuat sistem design login saya membutuhkan:
- 2 JLabel
- 2 JTextfiled
- 1 JPasswordfiled
- 2 Jbutton
Dan untuk mempercantik tampilan dengan menambahkan background saya menggunakan Jpanel , lalu saya pilih gambar yang sudah saya siapkan dan sesuai dengan aplikasi yang akan dibuat , atur letak gambar sebaik mungkin sehingga menjadi seperti gambar dibawah ini:
Berikut adalah source code yang saya gunakan untuk form login :
BTN LOGIN
String a = txtpassword.getText();
if (a.equals("Lansmaulana")||a.equals("12345")){
JOptionPane.showMessageDialog(null, "Sukses","Informasi", JOptionPane.INFORMATION_MESSAGE);
dispose();
datapenjualanlaptop1 Frm=new datapenjualanlaptop1();
Frm.setLocationRelativeTo(Frm);
Frm.setVisible(true);
}else {
JOptionPane.showMessageDialog(null,"Username dan Password Salah","Informasi",JOptionPane.WARNING_MESSAGE);
}
}
setelah itu kita akan memasuki password yang salah apakah aplikasi akan menditek itu salah contoh seperti gambar dibawah :
Dan sekarang kita bisa mencoba memasuki password yang benar contoh gambar berikut:
Setelah kita sukses memasukkan kata sandi dengan benar akan muncul aplikasi untuk penginputan seperti gambar dibawah:
Untuk membuat desain saya membutuhkan:
- 4 Jtexfiled
- 2 Panel
- 6 Jlabel
- 5 Button
Ditempatkan dan diatur sedemikian rupa hingga menjadi seperti gambar diatas.
Kita bisa langsung menginput data laptop yang kita jual dengan memasukkan ke colum colum yang sudah tersedia ,seperti gambar dibawah :
Setelah itu ada pilihan hitung, dimana dalam hitung itu akan menghitung harga satuan akan dikalikan dengan jumlah barang yang kita beli dan akan muncul total bayar yang harus kita bayar.
Contoh codingan seperti gambar dibawah :
gambar
Untuk bisa seperti itu berikut source codenya :
BTN HITUNG
int a = Integer.parseInt(txtsatuan.getText());
int b = Integer.parseInt(txtjumlah.getText());
int hasilnya = a * b;
txttotal.setText(" " + hasilnya);
Tombol button hapus untuk menghapus semua text saat kita malas menghapus manual, maka kita hanya harus menekan tombol hapus, maka semua text akan hilang seperti tampilan awal.
seperti gambar dibawah ini:
Untuk button simpan digunakan untuk proses penyimpanan ke database , semua pesanan akan tersimpan di database sesuai dengan apa yang dipesan , jangan lupa untuk mengkoneksikannya ke database terlebih dahulu, sudah terkoneksi ke database di lokalhost sudah tersimpan seperti gambar dibawah ini:
Selanjutnya adalah button cetak, button cetak untuk menampilkan report wizard seperti gambar dibawah ini:
Untuk bisa menampilkan seperti gambar diatas, maka kita perlu membuat reportnya terlebih dahulu
dibawah ini saya akan menjelaskan cara pembuatannya.
Pertma kita buat projek baru di netbeans, dan menbuat file report wizard
seperti gambar dibawahini:
lalu akan muncul tampilan seperti gambar di bawah ini:
pilih layout kemudian klik next
lalu akan muncul gambar seperti di bawah ini:
isi semua sesuai dengan data anda, seperti yang terlihat pada gambar di atas lalu klik next,
lalu akan muncul seperti gambar di bawah ini:
pilih sesuai data anda di Mysql lalu klik ok
akan muncul seperti gambar di bawah ini:
Selanjutnya klik next :
klik tombol >> makan akan terjadi seperti gambar di atas
Lalu klik next :
Isi sesusai keinginan anda tetapi saya menyarankan isi satu group 1 saja selanjutnya klik next :
Jika sudah seperti gambar di atas maka anda telah berhasil membuat report wizard ,dan klik finis :
Dan jika ingin mengedit, kita aktifkan tombol designernya, dan untuk menambahkan tulisan atau
semacamnya, anda hanya perlu mengklik lalu menggesernya ini sudah bisa diaplikasikan di netbaens anda.
dan ini adalah semua source kodenya
source code login:
/*
* 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 datapenjualanlaptop;
import javax.swing.JOptionPane;
/**
*
* @author Lansmaulana
*/
public class frmLogin extends javax.swing.JFrame {
/**
* Creates new form frmLogin
*/
public frmLogin() {
initComponents();
setTitle("Login");
}
/**
* 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();
txtusername = new javax.swing.JTextField();
txtpassword = new javax.swing.JPasswordField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
btnkeluar = new javax.swing.JButton();
btnlogin = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 51, 204));
txtusername.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtusernameActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel1.setText("Username");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Password");
btnkeluar.setBackground(new java.awt.Color(204, 0, 204));
btnkeluar.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
btnlogin.setBackground(new java.awt.Color(204, 0, 204));
btnlogin.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btnlogin.setText("Login");
btnlogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnloginActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
jLabel3.setText("Log In");
jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lansmaulana\\Downloads\\Login.png")); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(16, 16, 16)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnlogin)
.addGap(29, 29, 29)
.addComponent(btnkeluar))
.addComponent(txtusername, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtpassword, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(99, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(96, 96, 96)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtusername, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtpassword, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnkeluar)
.addComponent(btnlogin))
.addGap(150, 150, 150))))
);
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, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void txtusernameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnloginActionPerformed(java.awt.event.ActionEvent evt) {
String a = txtpassword.getText();
if (a.equals("Lansmaulana")||a.equals("12345")){
JOptionPane.showMessageDialog(null, "Sukses","Informasi", JOptionPane.INFORMATION_MESSAGE);
dispose();
datapenjualanlaptop1 Frm=new datapenjualanlaptop1();
Frm.setLocationRelativeTo(Frm);
Frm.setVisible(true);
}else {
JOptionPane.showMessageDialog(null,"Username dan Password Salah","Informasi",JOptionPane.WARNING_MESSAGE);
} // TODO add your handling code here:
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
/**
* @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(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(frmLogin.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 frmLogin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnkeluar;
private javax.swing.JButton btnlogin;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField txtpassword;
private javax.swing.JTextField txtusername;
// End of variables declaration
}
Source code data penjualan laptop
/*
* 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 datapenjualanlaptop;
import javax.swing.JOptionPane;
import java.awt.event.*;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
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;
/**
*
* @author Lansmaulana
*/
public class datapenjualanlaptop1 extends javax.swing.JFrame {
Connection koneksi;
/**
* Creates new form datapenjualanlaptop
*/
public datapenjualanlaptop1() {
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() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtmerek = new javax.swing.JTextField();
txtsatuan = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtjumlah = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
btnsimpan = new javax.swing.JButton();
btnhapus = new javax.swing.JButton();
btnlogout = new javax.swing.JButton();
btnhitung = new javax.swing.JButton();
txttotal = new javax.swing.JTextField();
btncetak = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jPanel1.setBackground(new java.awt.Color(204, 51, 255));
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
jLabel1.setText("Merek Laptop");
txtmerek.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtmerekActionPerformed(evt);
}
});
txtsatuan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtsatuanActionPerformed(evt);
}
});
jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
jLabel2.setText("Harga Satuan");
jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
jLabel3.setText("Jumlah Pembelian");
jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
jLabel4.setText("Total Bayar");
btnsimpan.setBackground(new java.awt.Color(153, 51, 255));
btnsimpan.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btnsimpan.setText("Simpan");
btnsimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsimpanActionPerformed(evt);
}
});
btnhapus.setBackground(new java.awt.Color(153, 51, 255));
btnhapus.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btnhapus.setText("Hapus");
btnhapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhapusActionPerformed(evt);
}
});
btnlogout.setBackground(new java.awt.Color(153, 51, 255));
btnlogout.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btnlogout.setText("Log Out");
btnlogout.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnlogoutActionPerformed(evt);
}
});
btnhitung.setBackground(new java.awt.Color(153, 51, 255));
btnhitung.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btnhitung.setText("Hitung");
btnhitung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhitungActionPerformed(evt);
}
});
btncetak.setBackground(new java.awt.Color(204, 51, 255));
btncetak.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
btncetak.setText("Cetak Pembelian");
btncetak.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btncetakActionPerformed(evt);
}
});
jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
jLabel5.setText("Penjualan Laptop Lenovo");
jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/datapenjualanlaptop/lenovo legion 2.jpg"))); // NOI18N
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 1, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(31, 31, 31)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnhapus)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
.addComponent(btnlogout))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(btnhitung)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnsimpan))
.addComponent(txtsatuan)
.addComponent(txtmerek, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtjumlah, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txttotal))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btncetak)
.addGap(127, 127, 127))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 415, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(234, 234, 234))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnhapus, btnhitung, btnlogout, btnsimpan});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtmerek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btncetak)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtsatuan)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtjumlah))
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnhitung, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnsimpan))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txttotal)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(45, 45, 45)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnlogout)
.addComponent(btnhapus))
.addGap(0, 263, Short.MAX_VALUE))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnhapus, btnhitung, btnlogout, btnsimpan});
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, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
public void buka_db() {
try {
Class.forName("com.mysql.jdbc.Driver");
koneksi = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/laptoplenovo", "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 txtsatuanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtmerek.setText("");
txtjumlah.setText("");
txtsatuan.setText("");
txttotal.setText("");
}
private void btnhitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a = Integer.parseInt(txtsatuan.getText());
int b = Integer.parseInt(txtjumlah.getText());
int hasilnya = a * b;
txttotal.setText(" " + hasilnya);
}
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
String host = "jdbc:mysql://localhost:3306/laptoplenovo",
user ="root",
pass ="";
Connection con = (Connection) DriverManager.getConnection(host, user, pass);
String Merek=txtmerek.getText();
int hargasatuan=Integer.parseInt(txtsatuan.getText());
int jumlahpembelian=Integer.parseInt(txtjumlah.getText());
String totalbayar=txttotal.getText();
Statement st=con.createStatement();
st.executeUpdate("INSERT INTO lenovo ( Merek_Barang , Harga_Satuan, Jumlah_pembelian , Total_Bayar )"
+ "VALUES ( '"+Merek+"',"+hargasatuan+" ,"+jumlahpembelian+" ,"+totalbayar+")");
st.close();
JOptionPane.showMessageDialog(null,"Berhasil");
} catch (SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void txtmerekActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
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;
JRP = JasperCompileManager.compileReport("src/datapenjualanlaptop/penjualanlaptop.jrxml");
JasperPrint JFILL = JasperFillManager.fillReport(JRP, maps, koneksi);
JasperViewer.viewReport(JFILL, false);
} catch (SQLException rptexcpt) {
JOptionPane.showMessageDialog(this, rptexcpt.getMessage());
System.out.println(rptexcpt);
} catch (JRException rptexcpt) {
JOptionPane.showMessageDialog(this, rptexcpt.getMessage());
System.out.println(rptexcpt);
}
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
buka_db();
}
private void btnlogoutActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(JOptionPane.showConfirmDialog(null,"Yakin Keluar","Konfirmasi",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){;
System.exit(0);
}
}
/**
* @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(datapenjualanlaptop1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(datapenjualanlaptop1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(datapenjualanlaptop1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(datapenjualanlaptop1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new datapenjualanlaptop1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btncetak;
private javax.swing.JButton btnhapus;
private javax.swing.JButton btnhitung;
private javax.swing.JButton btnlogout;
private javax.swing.JButton btnsimpan;
private javax.swing.ButtonGroup buttonGroup1;
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.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField txtjumlah;
private javax.swing.JTextField txtmerek;
private javax.swing.JTextField txtsatuan;
private javax.swing.JTextField txttotal;
// End of variables declaration
}
Demikian aplikasi sederhana yang saya buat, meskipun banyak sekali kekurangan didalamnya, saya harap bisa bermanfaat bagi teman -teman yang lain.
Wassalamualikum Wr Wb