Coding · Java · Task

Aplikasi Kasir Sederhana Berbasis Java + Database

Hai ~ Hai ~

Kali ini saya akan share yang (lagi-lagi) berbau coding. Aplikasi yang saya akan share ini berupa aplikasi kasir yang saat ini saya jadikan contoh warung ibu saya. Langsung saja kita bahas saja kuy ~

***

Deskripsi Singkat :

Aplikasi ini adalah aplikasi sederhana dari warung mpok illah. Akses atau fitur yang bisa Pemilik Warung gunakan antara lain:
– Membuat/Mengedit/Menghapus menu
– Melihat daftar menu
– Menghitung pesanan (kasir)
– Mencetak receipt (upcoming)

Aplikasi ini juga sudah terkoneksi dengan database. Berikut sql/database yang bisa Anda copy:

-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server version: 10.1.13-MariaDB - mariadb.org binary distribution
-- Server OS: Win32
-- HeidiSQL Version: 9.3.0.5111
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;




-- Dumping database structure for db_warung
DROP DATABASE IF EXISTS `db_warung`;
CREATE DATABASE IF NOT EXISTS `db_warung` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
USE `db_warung`;

-- Dumping structure for table db_warung.tb_menu
DROP TABLE IF EXISTS `tb_menu`;
CREATE TABLE IF NOT EXISTS `tb_menu` (
 `mn_id` int(11) NOT NULL AUTO_INCREMENT,
 `mn_code` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'MK- (Makanan) MN- (Minuman) CM-(Cemilan) - Angka',
 `mn_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
 `mn_price` double DEFAULT NULL,
 PRIMARY KEY (`mn_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Data exporting was unselected.
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

 

Design/Screenshot:

design_welcome_page
Gambar 1. Welcome Page

 

design_daftar_menu

Gambar 2. Daftar Menu

design_pembelian

Gambar 3. Menu Pembelian

design_pembelian_contoh

Gambar 4. Contoh pemakaian menu pembelian (kasir)

 

Source Code:

/*
 * 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 uas;

import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import java.util.regex.*;
import javax.swing.ListSelectionModel;




/**
 *
 * @author Administrator
 */
public class warung_mpok_illah extends javax.swing.JFrame {
 public static Connection con;
 public static Statement stm;
 /**
 * Creates new form warung_mpok_illah
 */
 public warung_mpok_illah() {
 initComponents();
 showData();
 }
 
 void connect(){
 try {
 String url ="jdbc:mysql://localhost/db_warung";
 String user="root";
 String pass="K3bunku_2014";
 Class.forName("com.mysql.jdbc.Driver");
 con =DriverManager.getConnection(url,user,pass);
 stm = con.createStatement();
 System.out.println("koneksi berhasil;");
 } catch (Exception e) {
 System.err.println("koneksi gagal" +e.getMessage());
 }
 }
 
 void showData(){
 DefaultTableModel dataModel = (DefaultTableModel) tbl_menu_daftar.getModel();

try{

connect();

String sql = "Select * from tb_menu order by mn_code asc";

ResultSet rs = stm.executeQuery(sql);

while (rs.next()){

dataModel.addRow(new Object[]{

rs.getString("mn_code"),

rs.getString("mn_name"),

rs.getDouble("mn_price"),

});

}




}catch (Exception e){

JOptionPane.showMessageDialog(null, "Ada Kesalahan");

}
 }
 
 public void setPanels(JPanel p, boolean hide){
 JFrame jframe = new JFrame();
 JPanel panel = p;
 jframe.setContentPane(panel);
 jframe.pack();
 jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
 if(!hide) jframe.setVisible(true);
 else jframe.setVisible(false);
 }

/**
 * 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() {

menu_daftar = new javax.swing.JPanel();
 jLabel5 = new javax.swing.JLabel();
 jScrollPane1 = new javax.swing.JScrollPane();
 tbl_menu_daftar = new javax.swing.JTable();
 jPanel1 = new javax.swing.JPanel();
 add_btn_submit = new javax.swing.JButton();
 add_menu_price = new javax.swing.JTextField();
 jLabel15 = new javax.swing.JLabel();
 add_menu_type = new javax.swing.JComboBox<>();
 jLabel14 = new javax.swing.JLabel();
 add_menu_name = new javax.swing.JTextField();
 jLabel13 = new javax.swing.JLabel();
 jPanel2 = new javax.swing.JPanel();
 remove_btn_submit = new javax.swing.JButton();
 edit_btn_submit = new javax.swing.JButton();
 jLabel16 = new javax.swing.JLabel();
 jLabel17 = new javax.swing.JLabel();
 menu_pembelian = new javax.swing.JPanel();
 jLabel9 = new javax.swing.JLabel();
 jLabel11 = new javax.swing.JLabel();
 jLabel12 = new javax.swing.JLabel();
 jScrollPane2 = new javax.swing.JScrollPane();
 txt_beli_menu = new javax.swing.JTextArea();
 btn_beli_hitung = new javax.swing.JButton();
 btn_beli_reset = new javax.swing.JButton();
 jScrollPane3 = new javax.swing.JScrollPane();
 txt_beli_output = new javax.swing.JTextArea();
 jLabel18 = new javax.swing.JLabel();
 jLabel1 = new javax.swing.JLabel();
 jLabel2 = new javax.swing.JLabel();
 jLabel3 = new javax.swing.JLabel();
 jLabel4 = new javax.swing.JLabel();
 link_menu = new javax.swing.JButton();
 link_pembelian = new javax.swing.JButton();

menu_daftar.setBackground(new java.awt.Color(255, 255, 255));

jLabel5.setFont(new java.awt.Font("Century Gothic", 1, 20)); // NOI18N
 jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
 jLabel5.setText("DAFTAR MENU");

tbl_menu_daftar.setModel(new javax.swing.table.DefaultTableModel(
 new Object [][] {

},
 new String [] {
 "Kode", "Nama Menu", "Harga"
 }
 ) {
 Class[] types = new Class [] {
 java.lang.String.class, java.lang.String.class, java.lang.Double.class
 };
 boolean[] canEdit = new boolean [] {
 false, true, true
 };

public Class getColumnClass(int columnIndex) {
 return types [columnIndex];
 }

public boolean isCellEditable(int rowIndex, int columnIndex) {
 return canEdit [columnIndex];
 }
 });
 tbl_menu_daftar.addInputMethodListener(new java.awt.event.InputMethodListener() {
 public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
 }
 public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
 tbl_menu_daftarInputMethodTextChanged(evt);
 }
 });
 tbl_menu_daftar.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
 public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
 tbl_menu_daftarVetoableChange(evt);
 }
 });
 jScrollPane1.setViewportView(tbl_menu_daftar);

add_btn_submit.setText("Buat Baru +");
 add_btn_submit.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 add_btn_submitActionPerformed(evt);
 }
 });

add_menu_price.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N

jLabel15.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel15.setText("Harga:");

add_menu_type.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Makanan", "Minuman", "Cemilan" }));

jLabel14.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel14.setText("Jenis:");

add_menu_name.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N

jLabel13.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel13.setText("Nama Menu:");

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()
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
 .addComponent(add_menu_price, javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(add_menu_type, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(add_menu_name, javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(add_btn_submit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 .addContainerGap())
 );
 jPanel1Layout.setVerticalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jLabel13)
 .addGap(8, 8, 8)
 .addComponent(add_menu_name, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(add_menu_type, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jLabel15)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(add_menu_price, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 .addComponent(add_btn_submit, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addContainerGap(14, Short.MAX_VALUE))
 );

remove_btn_submit.setText("Hapus");
 remove_btn_submit.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 remove_btn_submitActionPerformed(evt);
 }
 });

edit_btn_submit.setText("Edit");
 edit_btn_submit.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 edit_btn_submitActionPerformed(evt);
 }
 });

jLabel16.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel16.setText("Pilih/Klik list table untuk menghapus atau -");

jLabel17.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel17.setText(" mengubah serta menyimpan ke database.");

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
 jPanel2.setLayout(jPanel2Layout);
 jPanel2Layout.setHorizontalGroup(
 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel2Layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(remove_btn_submit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
 .addComponent(edit_btn_submit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 .addContainerGap())
 );
 jPanel2Layout.setVerticalGroup(
 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel2Layout.createSequentialGroup()
 .addGap(35, 35, 35)
 .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(18, 18, 18)
 .addComponent(remove_btn_submit, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(edit_btn_submit, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(36, 36, 36))
 );

javax.swing.GroupLayout menu_daftarLayout = new javax.swing.GroupLayout(menu_daftar);
 menu_daftar.setLayout(menu_daftarLayout);
 menu_daftarLayout.setHorizontalGroup(
 menu_daftarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(menu_daftarLayout.createSequentialGroup()
 .addContainerGap()
 .addGroup(menu_daftarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
 .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(menu_daftarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 .addContainerGap())
 );
 menu_daftarLayout.setVerticalGroup(
 menu_daftarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(menu_daftarLayout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jLabel5)
 .addGap(18, 18, 18)
 .addGroup(menu_daftarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(menu_daftarLayout.createSequentialGroup()
 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(0, 0, Short.MAX_VALUE))
 .addComponent(jScrollPane1))
 .addContainerGap())
 );

menu_pembelian.setBackground(new java.awt.Color(255, 255, 255));

jLabel9.setFont(new java.awt.Font("Century Gothic", 1, 20)); // NOI18N
 jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
 jLabel9.setText("PEMBELIAN");

jLabel11.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel11.setText("Isi makanan/minuman/cemilan yang di beli dibawah ini:");

jLabel12.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel12.setText("Ketikan kode atau nama menu, dan buat baris baru untuk menulis menu lainnya.");

txt_beli_menu.setColumns(20);
 txt_beli_menu.setRows(5);
 txt_beli_menu.setText("Contoh NamaMenu1 = JumlahNamaMenu1\nContoh KodeMenu2 = JumlahKodeMenu2");
 jScrollPane2.setViewportView(txt_beli_menu);

btn_beli_hitung.setText("HITUNG");
 btn_beli_hitung.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 btn_beli_hitungActionPerformed(evt);
 }
 });

btn_beli_reset.setText("Reset");
 btn_beli_reset.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 btn_beli_resetActionPerformed(evt);
 }
 });

txt_beli_output.setColumns(20);
 txt_beli_output.setRows(5);
 txt_beli_output.setEnabled(false);
 jScrollPane3.setViewportView(txt_beli_output);

jLabel18.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
 jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel18.setText("Output:");

javax.swing.GroupLayout menu_pembelianLayout = new javax.swing.GroupLayout(menu_pembelian);
 menu_pembelian.setLayout(menu_pembelianLayout);
 menu_pembelianLayout.setHorizontalGroup(
 menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(menu_pembelianLayout.createSequentialGroup()
 .addContainerGap()
 .addGroup(menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 713, Short.MAX_VALUE)
 .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 713, Short.MAX_VALUE)
 .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 713, Short.MAX_VALUE)
 .addGroup(menu_pembelianLayout.createSequentialGroup()
 .addGroup(menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
 .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, menu_pembelianLayout.createSequentialGroup()
 .addComponent(btn_beli_reset, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(btn_beli_hitung, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)))
 .addGap(18, 18, 18)
 .addGroup(menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jScrollPane3)
 .addGroup(menu_pembelianLayout.createSequentialGroup()
 .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(0, 0, Short.MAX_VALUE)))))
 .addContainerGap())
 );
 menu_pembelianLayout.setVerticalGroup(
 menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(menu_pembelianLayout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jLabel9)
 .addGap(18, 18, 18)
 .addComponent(jLabel11)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jLabel12)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(menu_pembelianLayout.createSequentialGroup()
 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(menu_pembelianLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(btn_beli_reset, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
 .addComponent(btn_beli_hitung, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
 .addGroup(menu_pembelianLayout.createSequentialGroup()
 .addComponent(jLabel18)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jScrollPane3)))
 .addContainerGap())
 );

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 setBackground(new java.awt.Color(255, 255, 255));

jLabel1.setFont(new java.awt.Font("Century Gothic", 0, 15)); // NOI18N
 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel1.setText("NIM : 161021450277");

jLabel2.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
 jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
 jLabel2.setText("SELAMAT DATANG");

jLabel3.setFont(new java.awt.Font("Century Gothic", 0, 18)); // NOI18N
 jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
 jLabel3.setText("Di Aplikasi Kasir Warung Mpok ILLAH");

jLabel4.setFont(new java.awt.Font("Century Gothic", 0, 15)); // NOI18N
 jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
 jLabel4.setText("Nama : Anggraeni");

link_menu.setText("DAFTAR MENU");
 link_menu.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 link_menuActionPerformed(evt);
 }
 });

link_pembelian.setText("PEMBELIAN");
 link_pembelian.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 link_pembelianActionPerformed(evt);
 }
 });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 getContentPane().setLayout(layout);
 layout.setHorizontalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel1, 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)
 .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addGroup(layout.createSequentialGroup()
 .addComponent(link_menu, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(link_pembelian, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(0, 12, Short.MAX_VALUE))))
 );
 layout.setVerticalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(link_menu)
 .addComponent(link_pembelian))
 .addGap(38, 38, 38)
 .addComponent(jLabel2)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 .addComponent(jLabel3)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 268, Short.MAX_VALUE)
 .addComponent(jLabel4)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jLabel1)
 .addContainerGap())
 );

pack();
 }// </editor-fold>

private void link_menuActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 this.setPanels(menu_daftar, false);
 }

private void link_pembelianActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 this.setPanels(menu_pembelian, false);
 }

private void add_btn_submitActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 if(add_menu_name.getText() == "" || add_menu_price.getText() == ""){
 JOptionPane.showMessageDialog(null, "Nama menu dan harga wajib diisi!");
 return;
 }
 DefaultTableModel dataModel = (DefaultTableModel) tbl_menu_daftar.getModel();
 ArrayList list = new ArrayList<>();
 tbl_menu_daftar.setAutoCreateColumnsFromModel(true);
 
 String code = "MK-";
 if(add_menu_type.getSelectedIndex() == 1) code = "MN-";
 else if(add_menu_type.getSelectedIndex() == 2) code = "CM-";
 
 try{
 connect();
 String last = "SELECT * FROM tb_menu ORDER BY mn_id DESC LIMIT 1";
 ResultSet lastRs = stm.executeQuery(last);
 int no = 1;
 while(lastRs.next()){
 String jk = lastRs.getString("mn_code");
 String[] j = jk.split("-");
 no = no + Integer.parseInt(j[1]);
 }
 code = code+String.valueOf(no);
 }catch (Exception e){
 System.out.println("Data tidak ada");
 code = code+"1";
 }
 
 try{

String sql = "insert into tb_menu (mn_code, mn_name, mn_price) values ('"+code+"', '" +add_menu_name.getText()+"' , '"+Double.parseDouble(add_menu_price.getText())+"')";

stm.executeUpdate(sql);

con.close();

}catch (Exception e){

JOptionPane.showMessageDialog(null,"Proses tambah gagal/koneksi gagal..");

System.out.println(e.getMessage());

}
 
 list.add(code);
 list.add(add_menu_name.getText());
 list.add(Double.parseDouble(add_menu_price.getText()));
 dataModel.addRow(list.toArray());
 
 add_menu_name.setText("");
 add_menu_price.setText("");
 }

private void remove_btn_submitActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 int pos = tbl_menu_daftar.getSelectedRow();
 String code = (String) tbl_menu_daftar.getModel().getValueAt(pos, 0);
 String name = (String) tbl_menu_daftar.getModel().getValueAt(pos, 1);
 Double price = (Double) tbl_menu_daftar.getModel().getValueAt(pos, 2);
 
 try{
 connect();
 DefaultTableModel dataModel = (DefaultTableModel) tbl_menu_daftar.getModel();
 String sql = "delete from tb_menu where mn_code='"+code+"'";

stm.executeUpdate(sql);
 con.close();
 
 dataModel.setRowCount(0);
 showData();

}catch (Exception e){

JOptionPane.showMessageDialog(null,"Proses update gagal/koneksi gagal..");

System.out.println(e.getMessage());

} 
 
 }

private void tbl_menu_daftarVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException { 
 // TODO add your handling code here:
 }

private void tbl_menu_daftarInputMethodTextChanged(java.awt.event.InputMethodEvent evt) { 
 // TODO add your handling code here:
 }

private void edit_btn_submitActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 int pos = tbl_menu_daftar.getSelectedRow();
 String code = (String) tbl_menu_daftar.getModel().getValueAt(pos, 0);
 String name = (String) tbl_menu_daftar.getModel().getValueAt(pos, 1);
 Double price = (Double) tbl_menu_daftar.getModel().getValueAt(pos, 2);
 
 try{
 connect();
 String sql = "UPDATE tb_menu SET mn_name='"+name+"', mn_price='"+price+"' WHERE mn_code='"+code+"'";
 System.out.println(code + name + price);
 stm.executeUpdate(sql);

con.close();

}catch (Exception e){

JOptionPane.showMessageDialog(null,"Proses update gagal/koneksi gagal..");

System.out.println(e.getMessage());

} 
 }

private void btn_beli_hitungActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 //txt_beli_menu
 String[] data = txt_beli_menu.getText().split("\\n");
 
 ArrayList output = new ArrayList(); int total = 0;
 for(int x=0; x < data.length; x++){
 try{
 String[] pesanan = data[x].split("=");
 String p = pesanan[0].trim(); 
 Double j = 0.0;
 try{
 j = Double.parseDouble(pesanan[1].trim());
 }catch(java.lang.NumberFormatException e){
 System.out.println("Tidak terdefinisi");
 }
 Double harga = 0.0;
 try{
 connect();
 String last = "SELECT * FROM tb_menu WHERE mn_code='"+p+"' OR mn_name='"+p+"';";
 ResultSet lastRs = stm.executeQuery(last);
 int no = 1;
 while(lastRs.next()){
 Double h = lastRs.getDouble("mn_price");
 harga = h * j;
 }
 }catch (Exception e){
 System.out.println("Data tidak ada");
 }

if(harga.intValue() != 0){
 output.add(p+" ("+j+") : "+harga.intValue());
 total = total + harga.intValue();
 }else{
 output.add(p+" ("+j+") : Data tidak ditemukan");
 }
 }catch(java.lang.ArrayIndexOutOfBoundsException e){
 System.out.println("Data tidak ditemukan");
 }
 }
 output.add("Total harga : "+total);
 txt_beli_output.setText(String.join("\n", output));
 }

private void btn_beli_resetActionPerformed(java.awt.event.ActionEvent evt) { 
 // TODO add your handling code here:
 txt_beli_menu.setText("");
 txt_beli_output.setText("");
 }

/**
 * @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(warung_mpok_illah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (InstantiationException ex) {
 java.util.logging.Logger.getLogger(warung_mpok_illah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (IllegalAccessException ex) {
 java.util.logging.Logger.getLogger(warung_mpok_illah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
 java.util.logging.Logger.getLogger(warung_mpok_illah.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 warung_mpok_illah().setVisible(true);
 }
 });
 }

// Variables declaration - do not modify 
 private javax.swing.JButton add_btn_submit;
 private javax.swing.JTextField add_menu_name;
 private javax.swing.JTextField add_menu_price;
 private javax.swing.JComboBox<String> add_menu_type;
 private javax.swing.JButton btn_beli_hitung;
 private javax.swing.JButton btn_beli_reset;
 private javax.swing.JButton edit_btn_submit;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel11;
 private javax.swing.JLabel jLabel12;
 private javax.swing.JLabel jLabel13;
 private javax.swing.JLabel jLabel14;
 private javax.swing.JLabel jLabel15;
 private javax.swing.JLabel jLabel16;
 private javax.swing.JLabel jLabel17;
 private javax.swing.JLabel jLabel18;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel9;
 private javax.swing.JPanel jPanel1;
 private javax.swing.JPanel jPanel2;
 private javax.swing.JScrollPane jScrollPane1;
 private javax.swing.JScrollPane jScrollPane2;
 private javax.swing.JScrollPane jScrollPane3;
 private javax.swing.JButton link_menu;
 private javax.swing.JButton link_pembelian;
 private javax.swing.JPanel menu_daftar;
 private javax.swing.JPanel menu_pembelian;
 private javax.swing.JButton remove_btn_submit;
 private javax.swing.JTable tbl_menu_daftar;
 private javax.swing.JTextArea txt_beli_menu;
 private javax.swing.JTextArea txt_beli_output;
 // End of variables declaration 
}

 

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

w

Connecting to %s