Program Transaksi Penjualan
TRANSAKSI PENJUALAN
contoh sudah jadi ,,,,,
ok ga usah basa kedaluwarsa lagi pribadi aja coyy ,,,
pertama" klik new project lalu next akan muncul menyerupai gambar berikut ketik nama project terserah anda aja yang penting jangan kosong udah ,,,
hehehee ,,,,,
setelah berhasil muncul gambar seprti ini :
klik kanan pada package input plih JframeForm lalu next ,,,
seperti gambar berikut :
ketik name class nya transaksi_penjualan,,,
setelah menciptakan class maka akan muncul gambar menyerupai berikut ,,,
nah kini kiprah anda desain menyerupai ini ,,,
Setelah itu klik kanan pada jTable1 pada table content ,,
pilih columns insert hingga 7 columns ,,,
dan ubah title nya
seperti ini coyy ,,,
kemudian kanan edit text pada
Jlabel sehingga desain nya menjadi kayak gini ,,,
buat koneksi pada aktivitas kita buat di sini
saya menggunakan xampp di class paling pertama ,,,
seperti ini :
cooding :
package market;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
public class Transaksi_penjualan extends javax.swing.JFrame {
private String user="root";
private String pwd ="";
private String host="localhost";
private String db="db_toko";
private String url="";
private Connection Lconnection=null;
private JTable table=null;
private Object model;
public Transaksi_penjualan() {
initComponents();
setTitle("Transaksi penjualan");
setFont(new java.awt.Font("ARIAL", 0, 10));
try {
Class.forName("com.mysql.jdbc.Driver");
url="jdbc:mysql://"+"localhost"+"/"+"db_toko"+"?user="+"root"+"&password="+"";
Lconnection=DriverManager.getConnection(url);
}
catch(ClassNotFoundException e) {
System.out.println("Driver_tidak_ditemukan");
}
catch (SQLException e){
System.out.println("koneksi gagal:" +
e.toString());
}
tampilTabel();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
kd_brg = new javax.swing.JTextField();
nm_brg = new javax.swing.JTextField();
diskon = new javax.swing.JTextField();
hrg_jual = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
tjum = new javax.swing.JTextField();
trusak = new javax.swing.JTextField();
tsisa = new javax.swing.JTextField();
btn_tmbh = new javax.swing.JButton();
btn_hpus = new javax.swing.JButton();
btn_exit = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel12 = new javax.swing.JLabel();
btn_cek = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setName("Transaksi Penjualan"); // NOI18N
jLabel1.setFont(new java.awt.Font("Arial Black", 1, 24));
jLabel1.setForeground(new java.awt.Color(51, 51, 255));
jLabel1.setText("TABEL DATA BARANG");
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null},
{null, null, null, null, null, null, null},
{null, null, null, null, null, null, null},
{null, null, null, null, null, null, null}
},
new String [] {
"Kode Barang", "Nama Barang", "Diskon", "Harga Jual", "Jumlah Barang", "Rusak", "Sisa"
}
));
jScrollPane1.setViewportView(jTable1);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel2.setForeground(new java.awt.Color(255, 102, 102));
jLabel2.setText("INPUT DATA BARANG");
jLabel3.setText("Kode Barang :");
jLabel4.setText("Nama Barang :");
jLabel5.setText("Diskon :");
jLabel6.setText("Harga Jual :");
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel7.setText("DATA BARANG");
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel8.setText("Stok Barang");
jLabel9.setText("Jumlah Barang :");
jLabel10.setText("Rusak :");
jLabel11.setText("Sisa :");
btn_tmbh.setText("Tambah");
btn_tmbh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_tmbhActionPerformed(evt);
}
});
btn_hpus.setText("Hapus");
btn_hpus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_hpusActionPerformed(evt);
}
});
btn_exit.setText("Exit");
btn_exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_exitActionPerformed(evt);
}
});
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel12.setForeground(new java.awt.Color(153, 153, 255));
jLabel12.setText("Cek menurut arahan barang");
btn_cek.setText("Cek");
btn_cek.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_cekActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel12))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(124, 124, 124)
.addComponent(btn_cek, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(31, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel12)
.addGap(18, 18, 18)
.addComponent(btn_cek, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(23, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_tmbh, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(12, 12, 12)
.addComponent(btn_hpus, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_exit, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel5)
.addComponent(jLabel4)
.addComponent(jLabel6))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(kd_brg, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nm_brg, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(diskon, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hrg_jual, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jLabel9))
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(trusak, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tsisa, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tjum, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel8))
.addGap(14, 14, 14))
.addComponent(jLabel2)))
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1)
.addGap(27, 27, 27)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(41, 41, 41)
.addComponent(jLabel2)
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(tjum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(trusak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tsisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)))
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(kd_brg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(nm_brg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(diskon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(hrg_jual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn_exit)
.addComponent(btn_hpus)
.addComponent(btn_tmbh))
.addGap(30, 30, 30))
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>
private void btn_tmbhActionPerformed(java.awt.event.ActionEvent evt) {
try{
Class.forName("com.mysql.jdbc.Driver");
url="jdbc:mysql://"+"localhost"+"/"+"db_toko"+"?user="+"root"+"&password="+"";
Connection
conn=DriverManager.getConnection(url);
PreparedStatement pStatement=null;
String sql="insert into barang"+"(kd_brg,nm_brg,diskon,hrg_jual,jumlah,rusak,sisa)"+"Values(?,?,?,?,?,?,?)";
pStatement=(PreparedStatement) conn.prepareStatement(sql);
pStatement.setString(1, kd_brg.getText());
pStatement.setString(2, nm_brg.getText());
pStatement.setString(3, diskon.getText());
pStatement.setString(4, hrg_jual.getText());
pStatement.setString(5, tjum.getText());
pStatement.setString(6, trusak.getText());
pStatement.setString(7, tsisa.getText());
int intTambah= pStatement.executeUpdate();
if(intTambah>0)
JOptionPane.showMessageDialog(this, "DATA TELAH SUKSES DISIMPAN","Informasi",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(this, "Penambahan gagal","Informasi",JOptionPane.INFORMATION_MESSAGE);
pStatement.close();
conn.close();
kd_brg.setText("");
nm_brg.setText("");
diskon.setText("");
hrg_jual.setText("");
tjum.setText("");
trusak.setText("");
tsisa.setText("");
}
catch(SQLException e){
System.out.println("koneksi gagal"+e.toString());
}
catch(ClassNotFoundException e){
System.out.println("jdbc.driver tidak ditemukan");
}
}
private void btn_hpusActionPerformed(java.awt.event.ActionEvent evt) {
String KodeBarang = table.getValueAt(
table.getSelectedRow(),0).toString();
try {
PreparedStatement pStatement = null;
String sql ="delete from barang " +
" where kd_brg=? ";
pStatement = Lconnection.prepareStatement(sql);
pStatement.setString(1, KodeBarang);
int intTambah= pStatement.executeUpdate();
if (intTambah>0)
JOptionPane.showMessageDialog(this,
"Hapus data sukses", "Informasi",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(this,
"Hapus data gagal", "Informasi",
JOptionPane.INFORMATION_MESSAGE);
pStatement.close();
tampilTabel();
}
catch (SQLException e){
System.out.println("koneksi gagal " + e.toString());
}
}
private void btn_exitActionPerformed(java.awt.event.ActionEvent evt) {
try {
int reply = JOptionPane.showConfirmDialog (this,
"Yakin Mau Keluar?",
"Sistem penjualan - Bye", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
if (reply == JOptionPane.YES_OPTION) {
setVisible (false);
dispose();
System.out.println ("Thank !!!");
System.out.println ("Cv. Budy_jufisal");
System.out.println ("\n2012");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.exit (0);
}
}
catch (Exception e) {
}
}
private void btn_cekActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
Statement stmt = Lconnection.createStatement();
ResultSet rslt = stmt.executeQuery("Select * from barang"
+ " where kd_brg='" + kd_brg.getText() + "'");
if (rslt.next()) {
btn_tmbh.setEnabled(true);
nm_brg.setText(rslt.getString("nm_brg"));
diskon.setText(rslt.getString("diskon"));
hrg_jual.setText(rslt.getString("hrg_jual"));
tjum.setText(rslt.getString("jumlah"));
trusak.setText(rslt.getString("rusak"));
tsisa.setText(rslt.getString("sisa"));
} else {
JOptionPane.showMessageDialog(this, "kode barang: Salah",
"Informasi", JOptionPane.INFORMATION_MESSAGE);
btn_tmbh.setEnabled(true);
kd_brg.setText("");
nm_brg.setText("");
diskon.setText("");
hrg_jual.setText("");
tjum.setText("");
trusak.setText("");
tsisa.setText("");
kd_brg.requestFocus();
}
} catch (SQLException e) {
System.out.println("koneksi gagal " + e.toString());
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Transaksi_penjualan().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btn_cek;
private javax.swing.JButton btn_exit;
private javax.swing.JButton btn_hpus;
private javax.swing.JButton btn_tmbh;
private javax.swing.JTextField diskon;
private javax.swing.JTextField hrg_jual;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
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.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField kd_brg;
private javax.swing.JTextField nm_brg;
private javax.swing.JTextField tjum;
private javax.swing.JTextField trusak;
private javax.swing.JTextField tsisa;
// End of variables declaration
private Object[][] getData(){
Object[][] data1= null;
try {
Statement stmt = Lconnection.createStatement();
ResultSet rslt = stmt.executeQuery(
"Select*from barang");
rslt.last();
int rowCount= rslt.getRow();
rslt.beforeFirst();
data1= new Object[rowCount][7];
int no=-1;
while (rslt.next()) {
no=no+1;
data1[no][0]=rslt.getString("kd_brg");
data1[no][1]=rslt.getString("nm_brg");
data1[no][2]=rslt.getString("diskon");
data1[no][3]=rslt.getString("hrg_jual");
data1[no][4]=rslt.getString("jumlah");
data1[no][5]=rslt.getString("rusak");
data1[no][6]=rslt.getString("sisa");
}
stmt.close();
}
catch (SQLException e){
System.out.println("koneksi gagal " +
e.toString());
}
return data1;
}
private void tampilTabel() {
String[] columnNames =
{"Kode Barang", "Nama barang","Diskon","Harga Jual","Jumlah Barang","Rusak","Sisa"};
table = new JTable(
getData(), columnNames);
jScrollPane1.setViewportView(table);
}
}
sehabis codiing run akan muncul menyerupai ini aktivitas nya ,,,
download sourcode di sini
terima kasih ,,,,,
Belum ada Komentar untuk "Program Transaksi Penjualan"
Posting Komentar