Aplikasi Rumah Makan


Selamat pagi siang atau malam kapanpun suasana yg sedang kalian alami skrg, kali ini saya akan berbagi project yg sudah dikerjakan selama berminggu minggu lamanya, Bertemakan rumah makan, Dimana disini akan berguna untuk seorang kasir dalam mengelola daftar paket makanan, Aplikasi ini dibuat bertujuan untuk memudahkan dan mempercepat dalam pengelolaan daftar paket dan transaksi yang tidak bisa terhitung oleh jari. Aplikasi ini hanya digunakan untuk kasir saja karena pembeli tidak dilibatkan, Oke pertama tama sebelum terjun ke pembuatan ada yang harus dipersiapkan dulu yaitu :

- MySQL(Untuk Database)
- Netbeans untuk Desain GUI dan Koding
- JasperReport (Untuk Laporan
Nah jika semua sudah dipersiapkan maka kita akan mulai dari :


1. Pembuatan database
Pertama kita buat dulu sebuah database bernama "RumahMakan" atau "Restoran" di localhost, lalu buat beberapa tabel dan field lalu isikan field setiap tabel , dibawah ini adalah kode SQL nya :
 
CREATE TABLE IF NOT EXISTS `detail_transaksi` (
`id_detail_transaksi` int(11) NOT NULL AUTO_INCREMENT,
`id_transaksi` int(11) NOT NULL,
`harga` int(11) NOT NULL,
`id_paket` varchar(10) NOT NULL, `jumlah` int(11) NOT NULL,
PRIMARY KEY (`id_detail_transaksi`)
`total_harga` int(11) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
INSERT INTO `detail_transaksi` (`id_detail_transaksi`, `id_transaksi`, `id_paket`, `harga`, `jumlah`, `total_harga`) VALUES
(1, 1, 'P001', 35000, 2, 70000), (2, 1, 'P001', 35000, 3, 105000); CREATE TABLE IF NOT EXISTS `kasir` ( `id_kasir` int(10) NOT NULL AUTO_INCREMENT, `username` varchar(10) NOT NULL,
INSERT INTO `kasir` (`id_kasir`, `username`, `password`, `nama_kasir`) VALUES
`password` varchar(50) NOT NULL, `nama_kasir` varchar(100) NOT NULL, PRIMARY KEY (`id_kasir`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
PRIMARY KEY (`id_paket`)
(2, 'admin', '2123', 'Ages'); CREATE TABLE IF NOT EXISTS `paket_makanan` ( `id_paket` varchar(10) NOT NULL, `nama_paket` varchar(25) NOT NULL, `keterangan` text NOT NULL, `harga` int(11) NOT NULL,
('P003', 'Chiken Big', 'Ayam, Teh Manis', 50000);
) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `paket_makanan` (`id_paket`, `nama_paket`, `keterangan`, `harga`) VALUES ('P001', 'Super Besar2', 'Ayam, Nasi', 35000), ('P002', 'Super Besar', 'Nasi, ayam, Pepsi', 25000),
INSERT INTO `transaksi` (`id_transaksi`, `id_kasir`, `tanggal`) VALUES
CREATE TABLE IF NOT EXISTS `transaksi` ( `id_transaksi` int(11) NOT NULL AUTO_INCREMENT, `id_kasir` int(11) NOT NULL, `tanggal` date NOT NULL, PRIMARY KEY (`id_transaksi`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; (1, 2, '2014-01-13');

2. Pembuatan Form
Buat 3 Form di Netbeans yaitu Daftar, Login dan Menu Utama, Desainnya sesuaikan seperti dibawah :

Form Login

Form Daftar

Form Menu


3. Pengkodingan
Langkah ke tiga kita mulai memulai koding. tetapi  kita diharuskan untuk menambah library dulu ke netbeansnya agar saat kompilasi tidak terjadi error.
Tambahkan library dibawah ini pada netbeans


Lalu buat 4 paket buat nyimpan class yang nanti akan dibuat:



Buat Class "koneksi.java" pada paket com.restoran.koneksi lalu isi dengan script dibawah
package com.restoran.koneksi;
import java.sql.*;
import javax.swing.JOptionPane;
public class koneksi {
public koneksi(){
private static Connection con; }
try{
public static Connection getConnection(){
}
con=DriverManager.getConnection("jdbc:mysql://localhost/rumahmakan","root",""); catch(SQLException e){
JOptionPane.showMessageDialog(null,"Gagal Koneksi"); } return con; }
}
Koding diatas berfungsi untuk mengkoneksikan data ke database yang berada pada localhost


Sesuaikan setiap koding dibawah ini pada setiap form.

 Form Daftar
package com.restoran.utama;
import com.restoran.koneksi.koneksi;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
public class Daftar extends javax.swing.JFrame {
import javax.swing.JOptionPane; Statement stt;
this.setLocationRelativeTo(null);
public Daftar() { initComponents(); }
//
@SuppressWarnings("unchecked")
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txt_username = new javax.swing.JTextField();
txt_pwd = new javax.swing.JPasswordField(); jLabel5 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
txt_nama_kasir = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("Daftar");
jButton1ActionPerformed(evt);
jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { } });
jLabel1.setText("Username");
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 230, 70, -1)); jLabel1.setForeground(new java.awt.Color(255, 255, 255));
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 160, -1, -1));
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, -1, -1)); jLabel2.setBackground(new java.awt.Color(0, 0, 0)); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel2.setText("Password");
getContentPane().add(txt_pwd, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 159, 154, -1));
jLabel3.setFont(new java.awt.Font("Friz Quadrata", 1, 18)); // NOI18N jLabel3.setText("Daftar Kasir"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 30, 130, 30)); getContentPane().add(txt_username, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 130, 154, -1));
jButton2.setText("Kembali");
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel5.setText("Nama Kasir"); getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 190, -1, -1)); getContentPane().add(txt_nama_kasir, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 190, 154, -1)); jButton2.addActionListener(new java.awt.event.ActionListener() {
getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 230, -1, -1)); jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/restoran/gambar/login daftar.jpg"))); // NOI18N pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Connection con = koneksi.getConnection(); try {
if(txt_nama_kasir.getText().equals("")||String.valueOf(txt_pwd.getPassword()).equals("")||txt_username.getText().equals("")){
JOptionPane.showMessageDialog(this, "Data ada yang Kosong", "Pesan", JOptionPane.ERROR_MESSAGE); } else{ stt = con.createStatement();
stt.executeUpdate(sql);
String sql = "INSERT INTO kasir(username,password,nama_kasir) VALUES('"+txt_username.getText()+"',md5('"+String.valueOf(txt_pwd.getPassword())+"'),'"+txt_nama_kasir.getText()+"')"; JOptionPane.showMessageDialog(rootPane, "Anda Telah Mendaftar"); login lgn = new login(); this.setVisible(false); lgn.setVisible(true);
login lgn = new login();
} } catch (Exception e) { JOptionPane.showMessageDialog(this, "Anda Gagal Mendaftar", "Pesan", JOptionPane.WARNING_MESSAGE); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false);
//
lgn.setVisible(true); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */
/* 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
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
*/ try { if ("Nimbus".equals(info.getName())) {
}
javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; }
java.util.logging.Logger.getLogger(Daftar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) { } catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Daftar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(Daftar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) {
//
} catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Daftar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); }
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
}
new Daftar().setVisible(true); }); }
private javax.swing.JButton jButton1;
// Variables declaration - do not modify private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3;
private javax.swing.JTextField txt_username;
private javax.swing.JLabel jLabel6; private javax.swing.JTextField txt_nama_kasir; private javax.swing.JPasswordField txt_pwd;
// End of variables declaration }



Form Menu
 
package com.restoran.utama;
import com.restoran.koneksi.koneksi;
import java.awt.Dimension;
import java.io.InputStream;
import java.awt.event.KeyEvent;
import java.sql.Statement;
import java.sql.Connection; import java.sql.ResultSet;
import java.util.HashMap;
import java.text.SimpleDateFormat; import java.util.Date;
import javax.swing.JTextField;
import javax.swing.JInternalFrame; import javax.swing.JOptionPane;
import net.sf.jasperreports.view.JasperViewer;
import javax.swing.table.DefaultTableModel; import net.sf.jasperreports.engine.*;
DefaultTableModel model;
public class formUtama extends javax.swing.JFrame { Statement stt; Statement stt2; ResultSet rss; String tgl;
tabel_makanan();
public formUtama() { initComponents(); jPanel1.setVisible(true); makanan.setVisible(false); tampil_tabel();
this.setLocationRelativeTo(null);
tabel_transaksi(); tampil_tabel_transaksi(); tglskrg(); no_transaksi(); kode_makanan(); } public JTextField id_kasir(){
//
return txt_id_kasir; } @SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
makanan = new javax.swing.JPanel();
btn_simpan = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton();
txtidmakanan = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel();
tbl_makanan = new javax.swing.JTable();
jLabel3 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); txtharga = new javax.swing.JTextField();
txtketerangan = new javax.swing.JTextArea();
txtnamapaket = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); transaksi = new javax.swing.JPanel();
jLabel16 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel();
txt_jumlah_t = new javax.swing.JTextField();
tgl_transaksi = new javax.swing.JTextField(); txt_no_transaksi = new javax.swing.JTextField(); txt_nama_paket = new javax.swing.JTextField(); cmb_kode = new javax.swing.JComboBox(); txt_harga_t = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); tbl_transaksi = new javax.swing.JTable(); jSeparator1 = new javax.swing.JSeparator(); jLabel6 = new javax.swing.JLabel(); txt_id_kasir = new javax.swing.JTextField();
jMenu1 = new javax.swing.JMenu();
txt_total_semua = new javax.swing.JTextField(); jLabel18 = new javax.swing.JLabel(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jLabel7 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenuItem2 = new javax.swing.JMenuItem();
getContentPane().setLayout(new java.awt.CardLayout());
jMenuItem3 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem4 = new javax.swing.JMenuItem(); jMenu3 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setResizable(false);
btn_simpan.addActionListener(new java.awt.event.ActionListener() {
jPanel1.setPreferredSize(new java.awt.Dimension(600, 500)); jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); getContentPane().add(jPanel1, "card3"); makanan.setPreferredSize(new java.awt.Dimension(600, 500)); makanan.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); btn_simpan.setText("Simpan");
makanan.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(193, 34, -1, -1));
public void actionPerformed(java.awt.event.ActionEvent evt) { btn_simpanActionPerformed(evt); } }); makanan.add(btn_simpan, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 290, -1, -1)); jLabel1.setFont(new java.awt.Font("Tekton Pro", 0, 18)); // NOI18N jLabel1.setText("FORM PAKET MAKANAN"); jButton2.setText("Ubah");
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); makanan.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 290, 66, -1)); jButton3.setText("Hapus"); jButton3.addActionListener(new java.awt.event.ActionListener() { jButton3ActionPerformed(evt);
});
} }); makanan.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 290, -1, -1)); jLabel4.setText("Harga"); makanan.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 250, -1, -1)); txtidmakanan.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txtidmakananActionPerformed(evt); }
new Object [][] {
makanan.add(txtidmakanan, new org.netbeans.lib.awtextra.AbsoluteConstraints(331, 110, 220, 30)); jLabel2.setText("ID Paket Makanan"); makanan.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 113, -1, -1)); jLabel3.setText("Nama Paket Makanan"); makanan.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 141, -1, -1)); tbl_makanan.setModel(new javax.swing.table.DefaultTableModel( {null, null, null, null}, {null, null, null, null},
makanan.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 315, 509, 179));
{null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); tbl_makanan.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tbl_makananMouseClicked(evt); } }); jScrollPane1.setViewportView(tbl_makanan); txtharga.addKeyListener(new java.awt.event.KeyAdapter() {
jScrollPane3.setViewportView(txtketerangan);
public void keyTyped(java.awt.event.KeyEvent evt) { txthargaKeyTyped(evt); } }); makanan.add(txtharga, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 250, 220, 30)); makanan.add(txtnamapaket, new org.netbeans.lib.awtextra.AbsoluteConstraints(331, 144, 220, -1)); jLabel5.setText("Keterangan"); makanan.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 182, -1, -1)); txtketerangan.setColumns(20); txtketerangan.setRows(5);
jLabel14.setText("Kode Paket Makanan");
makanan.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 176, 220, 70)); getContentPane().add(makanan, "card2"); transaksi.setPreferredSize(new java.awt.Dimension(600, 500)); transaksi.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel12.setText("Tanggal Transaksi"); transaksi.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 100, -1, -1)); jLabel13.setText("No Transaksi"); transaksi.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 140, -1, -1));
public void actionPerformed(java.awt.event.ActionEvent evt) {
transaksi.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 190, -1, -1)); jLabel15.setText("Nama Paket"); transaksi.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 220, -1, -1)); jLabel16.setText("Harga"); transaksi.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 250, -1, -1)); jLabel17.setText("Jumlah"); transaksi.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 290, -1, -1)); tgl_transaksi.setEditable(false); tgl_transaksi.addActionListener(new java.awt.event.ActionListener() { tgl_transaksiActionPerformed(evt);
transaksi.add(cmb_kode, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 190, 250, -1));
} }); transaksi.add(tgl_transaksi, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 100, 250, -1)); txt_no_transaksi.setEditable(false); transaksi.add(txt_no_transaksi, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, 93, -1)); txt_nama_paket.setEnabled(false); transaksi.add(txt_nama_paket, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 220, 250, -1)); cmb_kode.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { cmb_kodeItemStateChanged(evt); } }); txt_jumlah_t.setText("1");
});
txt_jumlah_t.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txt_jumlah_tKeyTyped(evt); } }); transaksi.add(txt_jumlah_t, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 280, 250, -1)); txt_harga_t.setEnabled(false); transaksi.add(txt_harga_t, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 250, 250, -1)); jButton7.setText("Beli"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); }
transaksi.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 170, 420, 10));
transaksi.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 320, -1, -1)); tbl_transaksi.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); jScrollPane2.setViewportView(tbl_transaksi); transaksi.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 350, 495, 95)); jLabel6.setFont(new java.awt.Font("Tekton Pro", 0, 18)); // NOI18N jLabel6.setText("FORM TRANSAKSI MAKANAN");
jLabel18.setText("Total");
transaksi.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 50, -1, -1)); jButton4.setText("Transaksi Selanjutnya"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); transaksi.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 130, 150, -1)); txt_id_kasir.setEditable(false); transaksi.add(txt_id_kasir, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 20, 50, -1)); txt_total_semua.setEditable(false); transaksi.add(txt_total_semua, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 460, 142, -1)); transaksi.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 460, -1, -1));
getContentPane().add(transaksi, "card4");
jButton5.setText("Hapus"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); transaksi.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 320, -1, -1)); jButton6.setText("Cetak"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); transaksi.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 460, -1, -1)); jLabel7.setText("Id Admin"); transaksi.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 20, -1, -1)); jMenu1.setText("Kasir");
jMenuItem4.setText("Daftar Paket");
jMenu1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenu1ActionPerformed(evt); } }); jMenuItem2.setText("Laporan Penjualan"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuItem3.setText("Log Out"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu1.add(jMenuItem3); jMenuBar1.add(jMenu1); jMenu2.setText("Makanan");
}//
jMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem4ActionPerformed(evt); } }); jMenu2.add(jMenuItem4); jMenuBar1.add(jMenu2); jMenu3.setText("Transaksi"); jMenuItem1.setText("Transaksi Penjualan"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu3.add(jMenuItem1); jMenuBar1.add(jMenu3); setJMenuBar(jMenuBar1); pack();
private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
jPanel1.setVisible(false); makanan.setVisible(true); }
// TODO add your handling code here:
private void txtidmakananActionPerformed(java.awt.event.ActionEvent evt) { }
clear();
private void btn_simpanActionPerformed(java.awt.event.ActionEvent evt) { Connection con = koneksi.getConnection(); try { if(btn_simpan.getText().equals("Batal")){ btn_simpan.setText("Simpan"); }
}
else{ if(txtidmakanan.getText().equals("")||txtnamapaket.getText().equals("")||txtketerangan.getText().equals("")||txtharga.getText().equals("")){ JOptionPane.showMessageDialog(this, "Mohon diisi data yang kosong", "Pesan", JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(rootPane, "Berhasil Masuk");
else{ stt = con.createStatement(); String sql = "INSERT INTO paket_makanan VALUES('"+txtidmakanan.getText()+"', '"+txtnamapaket.getText()+"','"+txtketerangan.getText()+"','"+txtharga.getText()+"')"; stt.executeUpdate(sql); tabel_makanan();
private void tbl_makananMouseClicked(java.awt.event.MouseEvent evt) {
tampil_tabel(); clear(); } } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Gagal"); } } int row = tbl_makanan.getSelectedRow();
btn_simpan.setText("Batal");
txtidmakanan.setText(tbl_makanan.getValueAt(row, 0).toString()); txtnamapaket.setText(tbl_makanan.getValueAt(row, 1).toString()); txtketerangan.setText(tbl_makanan.getValueAt(row, 2).toString()); txtharga.setText(tbl_makanan.getValueAt(row, 3).toString()); txtidmakanan.setEnabled(false);
JOptionPane.showMessageDialog(this, "Mohon pilih tabel terlebih dahulu","Pesan",JOptionPane.WARNING_MESSAGE);
} private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { Connection con = koneksi.getConnection(); int row = tbl_makanan.getSelectedRow(); try { stt = con.createStatement(); if(row == -1){ } else{
tabel_makanan();
String sql = "UPDATE paket_makanan SET nama_paket = '"+txtnamapaket.getText()+"'" + ", keterangan = '"+txtketerangan.getText()+"', harga = '"+txtharga.getText()+"' WHERE id_paket = '"+txtidmakanan.getText()+"'"; stt.executeUpdate(sql); JOptionPane.showMessageDialog(null, "Berhasil Diubah"); tampil_tabel(); clear(); btn_simpan.setText("Simpan");
int row = tbl_makanan.getSelectedRow();
} } catch (Exception e) { } } public void clear(){ txtharga.setText(""); txtidmakanan.setText(""); txtketerangan.setText(""); txtnamapaket.setText(""); txtidmakanan.setEnabled(true); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { Connection con = koneksi.getConnection(); try {
tampil_tabel();
stt = con.createStatement(); if(row == -1){ JOptionPane.showMessageDialog(this, "Mohon pilih tabel terlebih dahulu","Pesan",JOptionPane.WARNING_MESSAGE); } else{ String sql = "DELETE FROM paket_makanan WHERE id_paket = '"+txtidmakanan.getText()+"'"; stt.executeUpdate(sql); JOptionPane.showMessageDialog(null, "Berhasil Dihapus"); tabel_makanan(); clear();
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
btn_simpan.setText("Simpan"); } } catch (Exception e) { } } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { transaksi.setVisible(true); makanan.setVisible(false); jPanel1.setVisible(false); } no_transaksi(); tabel_transaksi(); tampil_tabel_transaksi(); txt_total_semua.setText("");
txt_harga_t.setText(rss2.getString("harga"));
} private void cmb_kodeItemStateChanged(java.awt.event.ItemEvent evt) { Connection con = koneksi.getConnection(); ResultSet rss2; String sql = "SELECT * FROM paket_makanan WHERE id_paket = '"+cmb_kode.getSelectedItem().toString()+"'"; try { stt = con.createStatement(); rss2 = stt.executeQuery(sql); if(rss2.next()){ txt_nama_paket.setText(rss2.getString("nama_paket")); } rss2.close();
if(txt_total_semua.getText().equals("")){
} catch (Exception e) { e.printStackTrace(); } } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { Connection con = koneksi.getConnection(); if(txt_jumlah_t.getText().equals("")){ JOptionPane.showMessageDialog(rootPane, "Data tidak boleh kosong"); } else{ int total = Integer.parseInt(txt_harga_t.getText()) * Integer.parseInt(txt_jumlah_t.getText()); int simpan2 = 0; simpan2 = 0;
JOptionPane.showMessageDialog(this, "Barang Berhasil Dibeli");
} else simpan2 = Integer.valueOf(txt_total_semua.getText()); String sql2 = "INSERT INTO detail_transaksi(id_transaksi,id_paket,harga,jumlah,total_harga) VALUES('"+txt_no_transaksi.getText()+"','"+cmb_kode.getSelectedItem().toString()+"','"+txt_harga_t.getText()+"','"+txt_jumlah_t.getText()+"','"+total+"')"; try { simpan_no(); stt2 = con.createStatement(); stt2.executeUpdate(sql2); txt_total_semua.setText(String.valueOf(simpan2+total));
}
tabel_transaksi(); tampil_tabel_transaksi(); } catch (Exception e) { e.printStackTrace(); } } } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { Connection con = koneksi.getConnection(); int row = tbl_transaksi.getSelectedRow(); try { stt = con.createStatement(); if(row == -1){ JOptionPane.showMessageDialog(this, "Anda Belum Memilih Tabel");
}
else{ int harga = Integer.parseInt((String) tbl_transaksi.getModel().getValueAt(row, 5)); int total = Integer.parseInt(txt_total_semua.getText()); String sql = "DELETE FROM detail_transaksi WHERE id_detail_transaksi = '"+tbl_transaksi.getModel().getValueAt(row, 0)+"'"; stt.executeUpdate(sql); JOptionPane.showMessageDialog(null, "Berhasil Dihapus"); txt_total_semua.setText(String.valueOf(total-harga)); tabel_transaksi(); tampil_tabel_transaksi(); clear();
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
} catch (Exception e) { } } private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) { login lgn = new login(); this.setVisible(false); lgn.setVisible(true); } private void tgl_transaksiActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } Connection con = koneksi.getConnection();
hash.put("idkasir", txt_id_kasir.getText());
String NamaFile = "/com/restoran/report/Struk_Pembayaran.jasper"; HashMap hash = new HashMap(); try { hash.put("idtransaksi", txt_no_transaksi.getText()); runReportDefault(NamaFile,hash); } catch (Exception e) { } } private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) { Connection con = koneksi.getConnection(); String NamaFile = "/com/restoran/report/laporan_penjualan.jasper"; HashMap hash = new HashMap(); try { runReportDefault(NamaFile,hash);
getToolkit().beep();
} catch (Exception e) { } } private void txthargaKeyTyped(java.awt.event.KeyEvent evt) { char c = evt.getKeyChar(); if (!((c >= '0') && (c <= '9') && txtharga.getText().length() < 10 || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) { getToolkit().beep(); evt.consume(); } } private void txt_jumlah_tKeyTyped(java.awt.event.KeyEvent evt) { char c = evt.getKeyChar(); if (!((c >= '0') && (c <= '9') && txt_jumlah_t.getText().length() < 10 || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) { evt.consume(); }
String sql = "INSERT INTO transaksi VALUES('"+txt_no_transaksi.getText()+"','"+txt_id_kasir.getText()+"','"+tgl+"')";
} public void runReportDefault(String sourcefilename, HashMap hash) { Connection con = koneksi.getConnection(); try { InputStream report; report = getClass().getResourceAsStream(sourcefilename); JasperPrint jprint = JasperFillManager.fillReport(report,hash, con); JasperViewer viewer = new JasperViewer(jprint, false); viewer.setFitPageZoomRatio(); viewer.setVisible(true); } catch (Exception e) { System.out.print(e.getMessage()); } } public void simpan_no(){ Connection con = koneksi.getConnection(); try { stt = con.createStatement();
o[1] = rss.getString("nama_paket");
stt.executeUpdate(sql); } catch (Exception e) { } } private void tabel_makanan(){ model = new DefaultTableModel(); tbl_makanan.setModel(model); model.addColumn("Id Paket Makanan"); model.addColumn("Nama Paket Makanan"); model.addColumn("Keterangan Paket"); model.addColumn("Harga"); } private void tampil_tabel(){ Connection con = koneksi.getConnection(); try { stt = con.createStatement(); String sql = "SELECT * FROM paket_makanan"; rss = stt.executeQuery(sql); while(rss.next()){ Object[] o; o = new Object[4]; o[0] = rss.getString("id_paket");
rss = stt.executeQuery(sql);
o[2] = rss.getString("keterangan"); o[3] = rss.getString("harga"); model.addRow(o); } } catch (Exception e) { e.printStackTrace(); } } //FORM TRANSAKSI public void tglskrg(){ Date skrg= new Date(); SimpleDateFormat format= new SimpleDateFormat("dd MMMM yyyy"); SimpleDateFormat format2= new SimpleDateFormat("yyyy-MM-dd"); tgl = format2.format(skrg); tgl_transaksi.setText(format.format(skrg)); } public void no_transaksi(){ Connection con = koneksi.getConnection(); String sql = "SELECT id_transaksi FROM transaksi"; try { stt = con.createStatement(); if(rss.last()){
model.addColumn("Id paket");
txt_no_transaksi.setText(String.valueOf(rss.getInt(1)+1)); } else txt_no_transaksi.setText("1"); } catch (Exception e) { } } public void kode_makanan(){ Connection con = koneksi.getConnection(); String sql = "SELECT * FROM paket_makanan"; try { stt = con.createStatement(); rss= stt.executeQuery(sql); while(rss.next()){ cmb_kode.addItem(rss.getString("id_paket")); } } catch (Exception e) { } } private void tabel_transaksi(){ model = new DefaultTableModel(); tbl_transaksi.setModel(model); model.addColumn("Id Detail Transaksi"); model.addColumn("No Transaksi"); model.addColumn("Harga");
public static void main(String args[]) {
model.addColumn("Jumlah"); model.addColumn("Total Harga"); } private void tampil_tabel_transaksi(){ Connection con = koneksi.getConnection(); try { stt = con.createStatement(); String sql = "SELECT * FROM detail_transaksi WHERE id_transaksi = '"+txt_no_transaksi.getText()+"'"; rss = stt.executeQuery(sql); while(rss.next()){ Object[] o; o = new Object[6]; o[0] = rss.getString(1); o[1] = rss.getString(2); o[2] = rss.getString(3); o[3] = rss.getString(4); o[4] = rss.getString(5); o[5] = rss.getString(6); model.addRow(o); } } catch (Exception e) { e.printStackTrace(); } }
//
/* Set the Nimbus look and feel */
/* 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
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
*/ try { if ("Nimbus".equals(info.getName())) {
}
javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; }
java.util.logging.Logger.getLogger(formUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) { } catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(formUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(formUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(formUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { }
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
}
new formUtama().setVisible(true); }); }
private javax.swing.JButton btn_simpan;
// Variables declaration - do not modify private javax.swing.JComboBox cmb_kode;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel12;
private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel2;
private javax.swing.JMenu jMenu1;
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.JMenu jMenu2;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenu jMenu3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JPanel jPanel1;
private javax.swing.JTable tbl_makanan;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JSeparator jSeparator1; private javax.swing.JPanel makanan; private javax.swing.JTable tbl_transaksi;
private javax.swing.JTextField txt_no_transaksi;
private javax.swing.JTextField tgl_transaksi; private javax.swing.JPanel transaksi; private javax.swing.JTextField txt_harga_t; private javax.swing.JTextField txt_id_kasir; private javax.swing.JTextField txt_jumlah_t; private javax.swing.JTextField txt_nama_paket;
private javax.swing.JTextField txt_total_semua; private javax.swing.JTextField txtharga; private javax.swing.JTextField txtidmakanan; private javax.swing.JTextArea txtketerangan; private javax.swing.JTextField txtnamapaket; // End of variables declaration }


Form Login
package com.restoran.utama;
import com.restoran.koneksi.koneksi;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
public class login extends javax.swing.JFrame {
import javax.swing.JOptionPane; Statement stt;
initComponents();
ResultSet rss; public login() {
@SuppressWarnings("unchecked")
this.setLocationRelativeTo(null); }
//
private void initComponents() {
txtusername = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
txtpassword = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton2 = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
setResizable(false);
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
getContentPane().add(txtusername, new org.netbeans.lib.awtextra.AbsoluteConstraints(178, 117, 154, -1));
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(55, 120, -1, -1));
jLabel1.setText("Username"); jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setText("Password");
jLabel3.setFont(new java.awt.Font("Friz Quadrata", 0, 18)); // NOI18N
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(55, 161, -1, -1)); jLabel3.setText("Login Kasir");
jButton1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 30, 120, 35)); getContentPane().add(txtpassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(178, 158, 154, -1));
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 200, 70, -1));
jButton1.setText("Login"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });
jButton2ActionPerformed(evt);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jButton2.setText("Daftar"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { } });
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 200, -1, -1)); jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/restoran/gambar/login daftar.jpg"))); // NOI18N pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Connection con = koneksi.getConnection(); formUtama frm = new formUtama(); try{
String sql = "SELECT * FROM kasir WHERE username = '"+txtusername.getText()+"' and password = md5('"+String.valueOf(txtpassword.getPassword())+"')";
stt = con.createStatement(); rss = stt.executeQuery(sql); if(rss.next()){
frm.setVisible(true);
JOptionPane.showMessageDialog(rootPane, "Login Berhasil"); frm.id_kasir().setText(rss.getString("id_kasir")); this.dispose();
e.printStackTrace();
} else JOptionPane.showMessageDialog(rootPane, "Gagal Login", "Pesan", JOptionPane.ERROR_MESSAGE); } catch(Exception e){ }
Daftar dft = new Daftar();
} private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); dft.setVisible(true);
//
} /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */
/* 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
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
*/ try { if ("Nimbus".equals(info.getName())) {
}
javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; }
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) { } catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) {
//
} catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); }
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
}
new login().setVisible(true); }); }
private javax.swing.JButton jButton1;
// Variables declaration - do not modify private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3;
// End of variables declaration
private javax.swing.JPasswordField txtpassword; private javax.swing.JTextField txtusername; }


Alhamdulilah sudah beres, sekarang kita tinggal coba aplikasinya , dan kurang lebih untuk penampakan nanti akan terlihat seperti dibawah ini ..
 
0 Komentar untuk "Aplikasi Rumah Makan"

Silakan tinggalkan komentar anda. DILARANG KERAS menyimpan link blog/web pada komentar dengan tujuan backlink, Spam.

 
Copyright © 2014 Tutorial Kampus - All Rights Reserved
Template By. Catatan Info