1. Penjelasan Program
Pada kesempatan kali ini saya akan menjelaskan bagaimana cara membuat aplikasi "Program Kasir Sederhana". Disini saya telah menbuat sebuah program kasir sederhana dengan menggunakan bahasa java. Fungsi program ini adalah sebagai mesin hitung otomastis untuk mempermudah kita untuk menghitung total pesanan yang akan dibayarkan oleh pelanggan.
2. FlowChart
3. Screen Shoot Aplikasi
4. Sourch Code
import javax.swing.JOptionPane;
/*
* 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.
*/
/**
*
*
@author rifa
*/
public class ulangcoba extends
javax.swing.JFrame {
/**
* Creates new form ulangcoba
*/
public ulangcoba() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the
form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed"
desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
btnayam1 = new javax.swing.JRadioButton();
btnayam2 = new javax.swing.JRadioButton();
btnayam3 = new javax.swing.JRadioButton();
btnayam4 = new javax.swing.JRadioButton();
btnminum1 = new javax.swing.JRadioButton();
btnminum2 = new javax.swing.JRadioButton();
btnminum3 = new javax.swing.JRadioButton();
btnhitung = new javax.swing.JButton();
btnhitung1 = new javax.swing.JButton();
btnkeluar = new javax.swing.JButton();
x1 = new javax.swing.JLabel();
x2 = new javax.swing.JLabel();
x3 = new javax.swing.JLabel();
x4 = new javax.swing.JLabel();
x5 = new javax.swing.JLabel();
x6 = new javax.swing.JLabel();
x7 = new javax.swing.JLabel();
jmlh1 = new javax.swing.JTextField();
jmlh2 = new javax.swing.JTextField();
jmlh3 = new javax.swing.JTextField();
jmlh4 = new javax.swing.JTextField();
jmlh5 = new javax.swing.JTextField();
jmlh6 = new javax.swing.JTextField();
jmlh7 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jmlhtotal = new javax.swing.JTextField();
lblayam1 = new javax.swing.JTextField();
lblayam2 = new javax.swing.JTextField();
lblayam3 = new javax.swing.JTextField();
lblayam4 = new javax.swing.JTextField();
lblminum1 = new javax.swing.JTextField();
lblminum2 = new javax.swing.JTextField();
lblminum3 = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED,
null, new java.awt.Color(204, 204, 255), null, null));
jLabel1.setFont(new java.awt.Font("Coneria Script Demo", 0,
18)); // NOI18N
jLabel1.setText("Kasir");
javax.swing.GroupLayout jPanel2Layout = new
javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(183, 183, 183)
.addComponent(jLabel1))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(9, 9, 9)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel1.add(jPanel2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, -7, 420, 50));
btnayam1.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnayam1.setText("Ayam Bakar");
btnayam1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnayam1ActionPerformed(evt);
}
});
jPanel1.add(btnayam1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(28, 81, -1, -1));
btnayam2.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnayam2.setText("Ayam Penyet");
btnayam2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnayam2ActionPerformed(evt);
}
});
jPanel1.add(btnayam2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(28, 112, -1, -1));
btnayam3.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnayam3.setText("Ayam Goreng");
btnayam3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnayam3ActionPerformed(evt);
}
});
jPanel1.add(btnayam3, new org.netbeans.lib.awtextra.AbsoluteConstraints(28,
143, -1, -1));
btnayam4.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnayam4.setText("Ayam Tepung");
btnayam4.addActionListener(new java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
btnayam4ActionPerformed(evt);
}
});
jPanel1.add(btnayam4, new
org.netbeans.lib.awtextra.AbsoluteConstraints(28, 174, -1, -1));
btnminum1.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnminum1.setText("Es Teh Manis");
btnminum1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnminum1ActionPerformed(evt);
}
});
jPanel1.add(btnminum1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(28, 215, -1, -1));
btnminum2.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnminum2.setText("Air
Mineral");
btnminum2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnminum2ActionPerformed(evt);
}
});
jPanel1.add(btnminum2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(28, 241, -1, -1));
btnminum3.setFont(new java.awt.Font("Giddyup Std", 0, 18)); //
NOI18N
btnminum3.setText("Soda");
btnminum3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnminum3ActionPerformed(evt);
}
});
jPanel1.add(btnminum3, new org.netbeans.lib.awtextra.AbsoluteConstraints(28,
267, -1, -1));
btnhitung.setText("Hitung");
btnhitung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhitungActionPerformed(evt);
}
});
jPanel1.add(btnhitung, new
org.netbeans.lib.awtextra.AbsoluteConstraints(52, 348, -1, -1));
btnhitung1.setText("Mulai");
btnhitung1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhitung1ActionPerformed(evt);
}
});
jPanel1.add(btnhitung1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(160, 348, -1, -1));
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
jPanel1.add(btnkeluar, new
org.netbeans.lib.awtextra.AbsoluteConstraints(272, 348, -1, -1));
x1.setText("x");
jPanel1.add(x1, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
85, -1, -1));
x2.setText("x");
jPanel1.add(x2, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
116, -1, -1));
x3.setText("x");
jPanel1.add(x3, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
147, -1, -1));
x4.setText("x");
jPanel1.add(x4, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
178, -1, -1));
x5.setText("x");
jPanel1.add(x5, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
219, -1, -1));
x6.setText("x");
jPanel1.add(x6, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
271, -1, -1));
x7.setText("x");
jPanel1.add(x7, new org.netbeans.lib.awtextra.AbsoluteConstraints(211,
245, -1, -1));
jmlh1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmlh1ActionPerformed(evt);
}
});
jPanel1.add(jmlh1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(235, 82, 30, -1));
jPanel1.add(jmlh2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(235, 113, 30, -1));
jPanel1.add(jmlh3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(235, 144, 30, -1));
jPanel1.add(jmlh4, new org.netbeans.lib.awtextra.AbsoluteConstraints(235,
175, 30, -1));
jPanel1.add(jmlh5, new
org.netbeans.lib.awtextra.AbsoluteConstraints(235, 216, 30, -1));
jPanel1.add(jmlh6, new
org.netbeans.lib.awtextra.AbsoluteConstraints(235, 242, 30, -1));
jPanel1.add(jmlh7, new org.netbeans.lib.awtextra.AbsoluteConstraints(235,
268, 30, -1));
jLabel2.setText("Total Pembelian");
jPanel1.add(jLabel2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(77, 313, -1, -1));
jmlhtotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmlhtotalActionPerformed(evt);
}
});
jPanel1.add(jmlhtotal, new
org.netbeans.lib.awtextra.AbsoluteConstraints(180, 310, 95, -1));
jPanel1.add(lblayam1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 82, 50, -1));
jPanel1.add(lblayam2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 113, 50, -1));
jPanel1.add(lblayam3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 144, 50, -1));
jPanel1.add(lblayam4, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 175, 50, -1));
jPanel1.add(lblminum1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 216, 50, -1));
jPanel1.add(lblminum2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 242, 50, -1));
lblminum3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
lblminum3ActionPerformed(evt);
}
});
jPanel1.add(lblminum3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(143, 268, 50, -1));
javax.swing.GroupLayout jPanel3Layout = new
javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel1.add(jPanel3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
getContentPane().add(jPanel1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 418, 382));
pack();
}// </editor-fold>
private void btnayam1ActionPerformed(java.awt.event.ActionEvent evt)
{
//UNTUK AYAM BAKAR//
int ayambakar=15000;
if(btnayam1.isSelected()){
lblayam1.setText(""+btnayam1.getText());
lblayam1.setText(""+ayambakar);
}else{
lblayam1.setText("");
}
}
private void btnayam2ActionPerformed(java.awt.event.ActionEvent evt)
{
//UNTUK AYAM PENYET
int ayampenyet=20000;
if(btnayam2.isSelected()){
lblayam2.setText(""+btnayam2.getText());
lblayam2.setText(""+ayampenyet);
}else{
lblayam2.setText("");
}
}
private void btnayam3ActionPerformed(java.awt.event.ActionEvent evt)
{
//UNTUK AYAM GORENG
int ayamgoreng=10000;
if(btnayam3.isSelected()){
lblayam3.setText(""+btnayam3.getText());
lblayam3.setText(""+ayamgoreng);
}else{
lblayam3.setText("");
}
// TODO add your handling code here:
}
private void btnayam4ActionPerformed(java.awt.event.ActionEvent evt)
{
//UNTUK AYAM TEPUNG
int ayamtepung=8000;
if(btnayam4.isSelected()){
lblayam4.setText(""+btnayam4.getText());
lblayam4.setText(""+ayamtepung);
}else{
lblayam4.setText("");
}
// TODO add your handling code here:
}
private void btnminum1ActionPerformed(java.awt.event.ActionEvent evt)
{
//UNTUK ES TEH
int estehmanis=5000;
if(btnminum1.isSelected()){
lblminum1.setText(""+btnminum1.getText());
lblminum1.setText(""+estehmanis);
}else{
lblminum1.setText("");
}
// TODO add your handling code here:
}
private void btnminum2ActionPerformed(java.awt.event.ActionEvent evt)
{
//UNTUK AIR MINERAL
int airmineral=3000;
if(btnminum2.isSelected()){
lblminum2.setText(""+btnminum2.getText());
lblminum2.setText(""+airmineral);
}else{
lblminum2.setText("");
}
// TODO add your handling code here:
}
private void btnminum3ActionPerformed(java.awt.event.ActionEvent evt)
{
// UNTUK SODA
int soda=6000;
if(btnminum3.isSelected()){
lblminum3.setText(""+btnminum3.getText());
lblminum3.setText(""+soda);
}else{
lblminum3.setText("");
}
// TODO add your handling code here:
}
private void btnhitungActionPerformed(java.awt.event.ActionEvent evt)
{
// UNTUK HITUNG
int total=0;
if(btnayam1.isSelected()){
String AB=jmlh1.getText();
int
jmlhAB=Integer.parseInt(AB);
int HargaAB=jmlhAB*15000;
total=total+HargaAB;
}
if(btnayam2.isSelected()){
String AP=jmlh2.getText();
int
jmlhAP=Integer.parseInt(AP);
int HargaAP=jmlhAP*20000;
total=total+HargaAP;
}
if(btnayam3.isSelected()){
String AG=jmlh3.getText();
int jmlhAG=Integer.parseInt(AG);
int HargaAG=jmlhAG*10000;
total=total+HargaAG;
}
if(btnayam4.isSelected()){
String AT=jmlh4.getText();
int jmlhAT=Integer.parseInt(AT);
int HargaAT=jmlhAT*8000;
total=total+HargaAT;
}
if(btnminum1.isSelected()){
String ET=jmlh5.getText();
int jmlhET=Integer.parseInt(ET);
int HargaET=jmlhET*5000;
total=total+HargaET;
}
if(btnminum2.isSelected()){
String AM=jmlh6.getText();
int
jmlhAM=Integer.parseInt(AM);
int HargaAM=jmlhAM*3000;
total=total+HargaAM;
}
if(btnminum3.isSelected()){
String SO=jmlh7.getText();
int
jmlhSO=Integer.parseInt(SO);
int HargaSO=jmlhSO*6000;
total=total+HargaSO;
}
jmlhtotal.setText("Rp"+total+",-");
// TODO add your handling code here:
}
private void btnhitung1ActionPerformed(java.awt.event.ActionEvent evt)
{
// UNTUK BUTTON MULAI
jmlh1.setEditable(false);
jmlh1.setText("");
jmlh2.setEditable(false);
jmlh2.setText("");
jmlh3.setEditable(false);
jmlh3.setText("");
jmlh4.setEditable(false);
jmlh4.setText("");
jmlh5.setEditable(false);
jmlh5.setText("");
jmlh6.setEditable(false);
jmlh6.setText("");
jmlh7.setEditable(false);
jmlh7.setText("");
// TODO add your handling code here:
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt)
{
int x= JOptionPane.showConfirmDialog(null,"Keluar
Program","Exit",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(x==JOptionPane.YES_OPTION){
System.exit(0);
}
}
private void jmlhtotalActionPerformed(java.awt.event.ActionEvent evt)
{
// // TODO add your
handling code here:
}
private void jmlh1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void lblminum3ActionPerformed(java.awt.event.ActionEvent evt)
{
// 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(ulangcoba.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ulangcoba.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ulangcoba.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ulangcoba.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new ulangcoba().setVisible(true);
});
}
// Variables declaration - do not modify
private javax.swing.JRadioButton btnayam1;
private javax.swing.JRadioButton btnayam2;
private javax.swing.JRadioButton btnayam3;
private javax.swing.JRadioButton btnayam4;
private javax.swing.JButton btnhitung;
private javax.swing.JButton btnhitung1;
private javax.swing.JButton btnkeluar;
private javax.swing.JRadioButton btnminum1;
private javax.swing.JRadioButton btnminum2;
private javax.swing.JRadioButton btnminum3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JTextField jmlh1;
private javax.swing.JTextField jmlh2;
private javax.swing.JTextField jmlh3;
private javax.swing.JTextField jmlh4;
private javax.swing.JTextField jmlh5;
private javax.swing.JTextField jmlh6;
private javax.swing.JTextField jmlh7;
private javax.swing.JTextField jmlhtotal;
private javax.swing.JTextField lblayam1;
private javax.swing.JTextField lblayam2;
private javax.swing.JTextField lblayam3;
private javax.swing.JTextField lblayam4;
private javax.swing.JTextField lblminum1;
private javax.swing.JTextField lblminum2;
private javax.swing.JTextField lblminum3;
private javax.swing.JLabel x1;
private javax.swing.JLabel x2;
private javax.swing.JLabel x3;
private javax.swing.JLabel x4;
private javax.swing.JLabel x5;
private javax.swing.JLabel x6;
private javax.swing.JLabel x7;
// End of variables declaration
}
Tidak ada komentar:
Posting Komentar