Aplikasi Pemesanan Menu Makanan

Tugas UTS

Kelompok 20

APLIKASI PEMESANAN MENU

MAKANAN DENGAN MENGGUNAKAN

PEMROGRAMAN JAVA DAN MY SQL

Oleh :

Frima Endriah N.

R.Gantria S.K.

Sehat Sempurna


A. Latar Belakang

  1. Kurangnya efisiensi pemesanan makan dengan cara antrian.
  2. Kesulitan konsumen dalam memesan makanan.

B. Rumusan Masalah

  1. Perangkat yang digunakanuntukpemesanan menu makanan
  2. Spesifikasi menu makanan

C. Batasan Masalah

  1. Pembuatan aplikasi sistem pemesanan menu makanan dengan menggunakan java.
  2. Pengolahan database pemesanan makanan dengan dengan menggunakan my SQL.
  3. Pembuatan tampilan aplikasi sistem pemesanan menu makanan dengan menggunakan GUI (Graphical User Interface).
  4. Pembuatan aplikasi pemesanan menu makanan ini hanya dibuat untuk satu inputan (prototype).

D. Tujuan

Tujuan dari pembuatan tugas UTS ini adalah sebagai berikut :

  1. Membuat algoritma yang tepat dalam sistem pemesana menu makanan secara otomatis.
  2. Pembuatan aplikasi yang dapat digunakan untuk memesan menu makanan.

E. Manfaat

  • Manfaat dari pembuatan tugas ini adalah untuk membantu user (konsumen) dalam melakukasn pemesanan menu makanan sehingga tidak perlu memanggil / mendatangi pelayan untuk memesan menu makanan yang akan dibeli ataupun sebaliknya.

F. Flow Chart

G. Tabel Database

Berilut ini adalah tampilan dari aplikasi pemesanan menu makanan yang telah dibuat.

  1. Menu Utama

Codingnya:

package program.pemesanan;

import java.sql.Connection;
import java.sql.Statement;
import javax.swing.JOptionPane;

public class MenuUtama extends javax.swing.JFrame {
Connection Con;
Statement Stat;
/** Creates new form MenuUtama */
public MenuUtama() {
initComponents();

}

private void initComponents() {

jLabel1 = new javax.swing.JLabel();
bLogin = new javax.swing.JButton();
bPesan = new javax.swing.JButton();
bExit = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();

jLabel1.setText(“jLabel1”);
jLabel1.setName(“jLabel1”);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“Form Order Makanan”);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

bLogin.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));
bLogin.setText(“Login”);
bLogin.setName(“bLogin”);
bLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bLoginActionPerformed(evt);
}
});
getContentPane().add(bLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 70, 90, 40));

bPesan.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));
bPesan.setText(“Pesan”);
bPesan.setName(“bPesan”);
bPesan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bPesanActionPerformed(evt);
}
});
getContentPane().add(bPesan, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 110, 90, 40));

bExit.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));
bExit.setText(“Exit”);
bExit.setName(“bExit”);
bExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bExitActionPerformed(evt);
}
});
getContentPane().add(bExit, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 200, 90, 40));

org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(MenuUtama.class);
jLabel2.setIcon(resourceMap.getIcon(“jLabel2.icon”));
jLabel2.setText(“jLabel2”);
jLabel2.setName(“jLabel2”);
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 300));

pack();
}

private void bLoginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Login x = new Login();
x.show();
dispose();
}

private void bPesanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Pemesanan2 x = new Pemesanan2();
x.show();
dispose();
}

private void bExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int exx = 0;
exx = JOptionPane.showConfirmDialog(null,”Anda yakin mau keluar aplikasi? “,”Warning”,JOptionPane.YES_NO_OPTION);
if (exx==JOptionPane.YES_OPTION)
System.exit(1);
else {
}
}
/**
* @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(MenuUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MenuUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MenuUtama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MenuUtama.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 MenuUtama().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JButton bExit;
private javax.swing.JButton bLogin;
private javax.swing.JButton bPesan;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}

  • Form ini tampil ketika kita menekan tombol exit yang ada pada menu utama.

2. Login

Codingnya :

package program.pemesanan;

import javax.swing.JOptionPane;

public class Login extends javax.swing.JFrame {

/** Creates new form Login */
public Login() {
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();
jLabel1 = new javax.swing.JLabel();
txtusername = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
txtpassword = new javax.swing.JPasswordField();
bLogin = new javax.swing.JButton();
bClose = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, “”, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font(“Matura MT Script Capitals”, 0, 16)));
jPanel1.setName(“jPanel1”);
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel1.setFont(new java.awt.Font(“Jokerman”, 1, 18));
jLabel1.setForeground(new java.awt.Color(0, 0, 153));
jLabel1.setText(“UserName”);
jLabel1.setName(“jLabel1”);
jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 80, 110, -1));

txtusername.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));
txtusername.setName(“txtusername”);
jPanel1.add(txtusername, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 80, 190, -1));

jLabel2.setFont(new java.awt.Font(“Jokerman”, 1, 18));
jLabel2.setForeground(new java.awt.Color(0, 0, 153));
jLabel2.setText(“Password”);
jLabel2.setName(“jLabel2”);
jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 120, 100, -1));

txtpassword.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));
txtpassword.setName(“txtpassword”);
jPanel1.add(txtpassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 120, 190, -1));

bLogin.setFont(new java.awt.Font(“Jokerman”, 1, 14));
bLogin.setForeground(new java.awt.Color(0, 0, 153));
bLogin.setText(“Login”);
bLogin.setName(“bLogin”);
bLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bLoginActionPerformed(evt);
}
});
jPanel1.add(bLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 190, 80, 30));

bClose.setFont(new java.awt.Font(“Jokerman”, 1, 14));
bClose.setForeground(new java.awt.Color(0, 0, 153));
bClose.setText(“Close”);
bClose.setName(“bClose”);
bClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bCloseActionPerformed(evt);
}
});
jPanel1.add(bClose, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 190, 80, -1));

jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/program/pemesanan/5 copy.png”)));
jLabel3.setName(“jLabel3”);
jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 230));

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

private void bLoginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (txtusername.getText().equals(“admin”) && txtpassword.getText().equals(“admin”))
{Pembayaran2 x = new Pembayaran2();
x.show();
dispose();}
else {
JOptionPane.showMessageDialog(null,”Password atau Username yang Anda masukkan salah!!!”);
}
}

private void bCloseActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MenuUtama x = new MenuUtama();
x.show();
dispose();
}

/**
* @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.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 Login().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JButton bClose;
private javax.swing.JButton bLogin;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField txtpassword;
private javax.swing.JTextField txtusername;
// End of variables declaration
}

3. Pemesanan

Codingnya :

package program.pemesanan;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class Pemesanan2 extends javax.swing.JFrame {
Connection Con;
Statement State;

DefaultTableModel tableModel = new DefaultTableModel(
new Object [][] {},new String [] {“Jenis Makanan”, “Qty”,”Harga”,”Total Harga”});
/** Creates new form Pemesanan2 */
public Pemesanan2() {
initComponents();
}
public void inisialtabel()
{
tblPesan.setModel(tableModel);
}
private void noOrder()
{
try {
Con = KoneksiDatabase.getKoneksi();
State = Con.createStatement();
String sql = “SELECT No_Order FROM headinputan”;
ResultSet rs = State.executeQuery(sql);
int brs = 0;
while (rs.next()) {
brs = rs.getRow();
}
if (brs == 0) {
txtorder.setText(“1”);
} else {
int nom=brs+1;
txtorder.setText(String.valueOf(nom));
}
rs.close();
} catch (SQLException e) {
System.out.println(“Error : ” + e);
}
}
public void simpanDatabase(){
try {
String order = txtorder.getText();
String meja = txtmeja.getText();
String subtotal = txtsubtotal.getText();
String hsql = “INSERT INTO headinputan values(‘”+order+”‘,'”+meja+”‘,'”+subtotal+”‘)”;
State.executeUpdate(hsql);
for (int i = 0; i < tblPesan.getRowCount(); i++) {
String Jenis_Makanan = (String) tblPesan.getValueAt(i, 0);
String Qty=(String) tblPesan.getValueAt(i, 1);
String Harga=(String) tblPesan.getValueAt(i, 2);
String Total_Harga=(String) tblPesan.getValueAt(i, 3);
String isql = “INSERT INTO inputan values(‘”+order+”‘,'”+Jenis_Makanan+”‘,'”+Qty+”‘,'”+Harga+”‘,'”+Total_Harga+”‘)”;
State.executeUpdate(isql);
}
} catch (SQLException e) {
System.out.println(“Error : ” + e);
}
}
public void hitungBayar (){
try {
int hitung =0;
for (int i = 0; i < tblPesan.getRowCount(); i++) {

String Total_Harga=(String) tblPesan.getValueAt(i, 3);
int iTotal_Harga = Integer.parseInt(Total_Harga);
hitung = (hitung+iTotal_Harga);
}
txtsubtotal.setText(String.valueOf(hitung));

} catch (Exception e){
System.out.println(“Error : ” + e);
}
}

/** 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();
txtqty = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtharga = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
txtdeskripsi = new javax.swing.JTextArea();
jLabel4 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtmeja = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
txtorder = new javax.swing.JTextField();
cmbmakanan = new javax.swing.JComboBox();
jScrollPane2 = new javax.swing.JScrollPane();
tblPesan = new javax.swing.JTable();
bPesan = new javax.swing.JButton();
bReset = new javax.swing.JButton();
bSave = new javax.swing.JButton();
bClose = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
txtsubtotal = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(“”));
jPanel1.setName(“jPanel1”);
jPanel1.setOpaque(false);
jPanel1.setLayout(null);

txtqty.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
txtqty.setName(“txtqty”);
jPanel1.add(txtqty);
txtqty.setBounds(170, 190, 140, 30);

jLabel6.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 17));
jLabel6.setText(“Qty”);
jLabel6.setName(“jLabel6”);
jPanel1.add(jLabel6);
jLabel6.setBounds(20, 190, 70, 30);

jLabel5.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
jLabel5.setText(“Harga (Rp)”);
jLabel5.setName(“jLabel5”);
jPanel1.add(jLabel5);
jLabel5.setBounds(20, 120, 90, 30);

txtharga.setEditable(false);
txtharga.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
txtharga.setName(“txtharga”);
jPanel1.add(txtharga);
txtharga.setBounds(170, 110, 140, 30);

jScrollPane1.setName(“jScrollPane1”);

txtdeskripsi.setColumns(20);
txtdeskripsi.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
txtdeskripsi.setRows(5);
txtdeskripsi.setName(“txtdeskripsi”);
jScrollPane1.setViewportView(txtdeskripsi);

jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(320, 140, 180, 80);

jLabel4.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
jLabel4.setText(“Deskripsi”);
jLabel4.setName(“jLabel4”);
jPanel1.add(jLabel4);
jLabel4.setBounds(460, 110, 90, 30);

jLabel3.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
jLabel3.setText(“Jenis Makanan”);
jLabel3.setName(“jLabel3”);
jPanel1.add(jLabel3);
jLabel3.setBounds(20, 70, 140, 30);

txtmeja.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
txtmeja.setName(“txtmeja”);
jPanel1.add(txtmeja);
txtmeja.setBounds(170, 150, 140, 30);

jLabel2.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
jLabel2.setText(“No Meja”);
jLabel2.setName(“jLabel2”);
jPanel1.add(jLabel2);
jLabel2.setBounds(20, 160, 90, 22);

jLabel1.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
jLabel1.setText(“No Order”);
jLabel1.setName(“jLabel1”);
jPanel1.add(jLabel1);
jLabel1.setBounds(330, 70, 90, 30);

txtorder.setEditable(false);
txtorder.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
txtorder.setName(“txtorder”);
jPanel1.add(txtorder);
txtorder.setBounds(440, 70, 125, 30);

cmbmakanan.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 16));
cmbmakanan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “-List Pilihan-“, “Paket A”, “Paket B”, “Paket C”, “Paket D” }));
cmbmakanan.setName(“cmbmakanan”);
cmbmakanan.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cmbmakananItemStateChanged(evt);
}
});
jPanel1.add(cmbmakanan);
cmbmakanan.setBounds(170, 70, 140, 30);

jScrollPane2.setName(“jScrollPane2”);

tblPesan.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 14));
tblPesan.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 [] {
“Jenis Makanan”, “Qty”, “Harga”, “Total Harga”
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};

public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tblPesan.setEnabled(false);
tblPesan.setName(“tblPesan”);
tblPesan.setOpaque(false);
jScrollPane2.setViewportView(tblPesan);

jPanel1.add(jScrollPane2);
jScrollPane2.setBounds(20, 230, 680, 130);

bPesan.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));
bPesan.setText(“Pesan”);
bPesan.setName(“bPesan”);
bPesan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bPesanActionPerformed(evt);
}
});
jPanel1.add(bPesan);
bPesan.setBounds(20, 380, 80, 30);

bReset.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));
bReset.setText(“Reset”);
bReset.setName(“bReset”);
bReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bResetActionPerformed(evt);
}
});
jPanel1.add(bReset);
bReset.setBounds(110, 380, 73, 30);

bSave.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));
bSave.setText(“Selesai & Save”);
bSave.setName(“bSave”);
bSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bSaveActionPerformed(evt);
}
});
jPanel1.add(bSave);
bSave.setBounds(190, 380, 150, 30);

bClose.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 14));
bClose.setText(“Close”);
bClose.setName(“bClose”); // NOI18N
bClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bCloseActionPerformed(evt);
}
});
jPanel1.add(bClose);
bClose.setBounds(630, 380, 70, 27);

jLabel7.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));
jLabel7.setText(“Total Pembayaran (Rp)”);
jLabel7.setName(“jLabel7”);
jPanel1.add(jLabel7);
jLabel7.setBounds(350, 380, 160, 30);

txtsubtotal.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));
txtsubtotal.setName(“txtsubtotal”);
jPanel1.add(txtsubtotal);
txtsubtotal.setBounds(514, 380, 110, 30);

jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/program/pemesanan/00 (327) copy.png”))); // NOI18N
jLabel8.setName(“jLabel8″);
jPanel1.add(jLabel8);
jLabel8.setBounds(0, 0, 720, 422);

getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 720, 420));

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

private void bCloseActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MenuUtama x = new MenuUtama();
x.show();
dispose();
}

private void bSaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,”Langsung tekan tombol Close”);

noOrder();
simpanDatabase();
hitungBayar();

int maxdata = tblPesan.getRowCount();
for (int i=0; i<maxdata;i++) {
String hitung = (String) tblPesan.getValueAt(i, 3);
int ihitung = Integer.parseInt(hitung);
}
String order = txtorder.getText();
String total = txtsubtotal.getText();
try {
String hsql = “INSERT INTO headinputan values”+”(‘”+order+”‘,'”+total+”‘)”;
State.executeUpdate(hsql);

} catch (SQLException ex) {
System.out.println(“Error : “+ex);
}

txtmeja.setText(null);
for (int i=0; i<tblPesan.getRowCount();i++){
tblPesan.removeAll();
}

}

private void bResetActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
cmbmakanan.setSelectedItem(“-List Pilihan-“);
txtharga.setText(null);
txtmeja.setText(null);
txtqty.setText(null);
txtdeskripsi.setText(null);
txtsubtotal.setText(null);
}

private void bPesanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (txtdeskripsi.getText().isEmpty()||txtmeja.getText().isEmpty()||txtqty.getText().isEmpty())
{JOptionPane.showMessageDialog(null,”Data belum lengkap!!!”);}
else {
int v = 0;
v = JOptionPane.showConfirmDialog(null,”Anda sudah yakin dengan pesanan Anda? “,”Warning”,JOptionPane.YES_NO_OPTION);
if (v==JOptionPane.YES_OPTION){
try {
String Jenis_Makanan = cmbmakanan.getSelectedItem().toString();
String Qty = txtqty.getText();
String Harga = txtharga.getText();
int iqty = Integer.parseInt(Qty);
int iharga  = Integer.parseInt(Harga);
int itotal = (iqty*iharga);
String Total_Harga = String.valueOf(itotal);
tableModel.addRow(new Object[]{Jenis_Makanan,Qty,Harga,Total_Harga});
inisialtabel();
} catch (Exception e) {
System.out.println(“Error : ” + e);
}
}
cmbmakanan.setSelectedItem(“-List Pilihan-“);
txtharga.setText(null);
txtqty.setText(null);
txtdeskripsi.setText(null);
}
hitungBayar();
}

private void cmbmakananItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
String pilih = cmbmakanan.getSelectedItem().toString();

if (pilih.equals(“Paket A”))
{txtdeskripsi.setText(“Nasi”+”\n”+”Iga Bakar”+”\n”+”Es Campur”);
int harga = 25000;
txtharga.setText(String.valueOf(harga));}
else
if (pilih.equals(“Paket B”))
{txtdeskripsi.setText(“Nasi”+”\n”+”Ayam Bakar”+”\n”+”Es Alpukat”);
int harga = 20000;
txtharga.setText(String.valueOf(harga));}
else
if (pilih.equals(“Paket C”))
{txtdeskripsi.setText(“Nasi”+”\n”+”Ikan Bakar”+”\n”+”Es Jeruk”);
int harga = 15000;
txtharga.setText(String.valueOf(harga));}
else
if (pilih.equals(“Paket D”))
{txtdeskripsi.setText(“Nasi Goreng”+”\n”+”Es Teh Manis”);
int harga = 10000;
txtharga.setText(String.valueOf(harga));}
else
{txtdeskripsi.setText(null);}
}

/**
* @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(Pemesanan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Pemesanan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Pemesanan2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Pemesanan2.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 Pemesanan2().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JButton bClose;
private javax.swing.JButton bPesan;
private javax.swing.JButton bReset;
private javax.swing.JButton bSave;
private javax.swing.JComboBox cmbmakanan;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable tblPesan;
private javax.swing.JTextArea txtdeskripsi;
private javax.swing.JTextField txtharga;
private javax.swing.JTextField txtmeja;
private javax.swing.JTextField txtorder;
private javax.swing.JTextField txtqty;
private javax.swing.JTextField txtsubtotal;
// End of variables declaration

private void x(String valueOf) {
throw new UnsupportedOperationException(“Not yet implemented”);
}
}

  • Form di bawah ini tampil ketika kita menekan tombol selesai dan save yang ada pada form pembayaran.

  • Form di bawah ini tampil ketika kita menekan tombol close yang ada pada form pemesanan.

4. Pembayaran

Untuk source code dalam pembuatan aplikasi ini dapat kita lihat seperti di bawah ini :

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/*

* Pembayaran2.java

*

* Created on Dec 10, 2011, 9:20:33 PM

*/

package program.pemesanan;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import javax.swing.JOptionPane;

import javax.swing.table.DefaultTableModel;

public class Pembayaran2 extends javax.swing.JFrame {

Connection con;

Statement state;

ResultSet rs;

private Object[][] isiTabel = null;

private String[] header = {“Jenis makanan”,”qty”,”harga”,”Total”};

private DefaultTableModel dtm;

/** Creates new form Pembayaran2 */

public Pembayaran2() {

initComponents();

}

public void hitungBayar (){

try {

int hitung =0;

for (int i = 0; i < tblpesan.getRowCount(); i++) {

String Total_Harga=(String) tblpesan.getValueAt(i, 3);

int iTotal_Harga = Integer.parseInt(Total_Harga);

hitung = (hitung+iTotal_Harga);

}

txttotalbayar.setText(String.valueOf(hitung));

} catch (Exception e){

System.out.println(“Error : ” + e);

}

}

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

jLabel3 = new javax.swing.JLabel();

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

txtorder = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

txttotalbayar = new javax.swing.JTextField();

bDelete = new javax.swing.JButton();

jpesan = new javax.swing.JScrollPane();

tblpesan = new javax.swing.JTable();

bClose = new javax.swing.JButton();

bReset = new javax.swing.JButton();

bHitung = new javax.swing.JButton();

jLabel5 = new javax.swing.JLabel();

txthapus = new javax.swing.JTextField();

jLabel4 = new javax.swing.JLabel();

jLabel6 = new javax.swing.JLabel();

jLabel7 = new javax.swing.JLabel();

jLabel3.setText(“jLabel3”);

jLabel3.setName(“jLabel3”);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

getContentPane().setLayout(new java.awt.GridLayout(1, 0));

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(“”));

jPanel1.setName(“jPanel1”);

jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel1.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));

jLabel1.setText(“No Order”);

jLabel1.setName(“jLabel1”);

jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 70, 100, 30));

txtorder.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));

txtorder.setName(“txtorder”);

txtorder.addInputMethodListener(new java.awt.event.InputMethodListener() {

public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {

}

public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {

txtorderInputMethodTextChanged(evt);

}

});

jPanel1.add(txtorder, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 70, 50, 30));

jLabel2.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));

jLabel2.setText(“Total Pembayaran”);

jLabel2.setName(“jLabel2”);

jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 100, 150, 22));

txttotalbayar.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));

txttotalbayar.setName(“txttotalbayar”);

jPanel1.add(txttotalbayar, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 90, 120, 30));

bDelete.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));

bDelete.setText(“Delete”);

bDelete.setName(“bDelete”);

bDelete.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

bDeleteActionPerformed(evt);

}

});

jPanel1.add(bDelete, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 260, 80, 30));

jpesan.setName(“jpesan”);

tblpesan.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 [] {

“Jenis Makanan”, “Qty”, “Harga”, “Total Harga”

}

) {

boolean[] canEdit = new boolean [] {

false, false, false, false

};

public boolean isCellEditable(int rowIndex, int columnIndex) {

return canEdit [columnIndex];

}

});

tblpesan.setCellSelectionEnabled(true);

tblpesan.setName(“tblpesan”);

jpesan.setViewportView(tblpesan);

jPanel1.add(jpesan, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 130, 480, 80));

bClose.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));

bClose.setText(“Close”);

bClose.setName(“bClose”);

bClose.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

bCloseActionPerformed(evt);

}

});

jPanel1.add(bClose, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 260, -1, -1));

bReset.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));

bReset.setText(“Reset”);

bReset.setName(“bReset”);

bReset.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

bResetActionPerformed(evt);

}

});

jPanel1.add(bReset, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 260, 80, 30));

bHitung.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 15));

bHitung.setText(“Hitung”);

bHitung.setName(“bHitung”);

bHitung.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

bHitungActionPerformed(evt);

}

});

jPanel1.add(bHitung, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 70, -1, -1));

jLabel5.setFont(new java.awt.Font(“MV Boli”, 1, 14));

jLabel5.setText(“Hapus No Order”);

jLabel5.setName(“jLabel5”);

jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 230, -1, -1));

txthapus.setName(“txthapus”);

jPanel1.add(txthapus, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 230, 90, -1));

jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/program/pemesanan/1.png”)));

jLabel4.setName(“jLabel4”);

jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 540, 320));

jLabel6.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));

jLabel6.setText(“No Order”);

jLabel6.setName(“jLabel6”);

jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 70, 100, 30));

jLabel7.setFont(new java.awt.Font(“Matura MT Script Capitals”, 0, 18));

jLabel7.setText(“No Order”);

jLabel7.setName(“jLabel7”);

jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 70, 100, 30));

getContentPane().add(jPanel1);

pack();

}// </editor-fold>

private void bHitungActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

bacaData();

hitungBayar();

}

private void bResetActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

txtorder.setText(null);

txthapus.setText(null);

txttotalbayar.setText(null);

}

private void bCloseActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

MenuUtama x = new MenuUtama();

x.show();

dispose();

}

private void bDeleteActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

/*String a = txthapus.getText();

if (a==null){

JOptionPane.showMessageDialog(null, “Hapus No Order tidak dipilih!”);

}*/

try{

String sql = “DELETE FROM inputan WHERE No_Order='”+(txthapus.getText())+”‘”;

String sql1 = “DELETE FROM headinputan WHERE No_Order='”+(txthapus.getText())+”‘”;

state.executeUpdate(sql);

state.executeUpdate(sql1);

bacaData();

}catch(SQLException e){

System.out.println(“Terjadi Error : “+e);

}

txtorder.setText(null);

txthapus.setText(null);

txttotalbayar.setText(null);

}

private void txtorderInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {

// TODO add your handling code here:

}

private void bacaData() {

try {

con=KoneksiDatabase.getKoneksi();

state = con.createStatement();

rs = state.executeQuery(“SELECT headinputan.No_order,inputan.Jenis_Makanan,inputan.Qty,inputan.Harga,inputan.Total_Harga,headinputan.Sub_total FROM inputan INNER JOIN headinputan ON inputan.No_Order=headinputan.No_Order WHERE inputan.No_Order='”+(txtorder.getText())+”‘”);

ResultSetMetaData meta =rs.getMetaData();

int col = meta.getColumnCount();

int baris = 0;

while (rs.next()) {

baris = rs.getRow();

}

isiTabel = new Object[baris][col];

int x = 0;

rs.beforeFirst();

while (rs.next()) {

isiTabel[x][0] = rs.getString(“Jenis_Makanan”);

isiTabel[x][1] = rs.getString(“Qty”);

isiTabel[x][2] = rs.getString(“Harga”);

isiTabel[x][3] = rs.getString(“Total_Harga”);

x++;

txttotalbayar.setText(rs.getString(“Sub_Total”));

}

tblpesan.setModel(new DefaultTableModel(isiTabel, header));

} catch (SQLException e) {

JOptionPane.showMessageDialog(null, e);

}

}

/**

* @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(Pembayaran2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Pembayaran2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Pembayaran2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Pembayaran2.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 Pembayaran2().setVisible(true);

}

});

}

// Variables declaration – do not modify

private javax.swing.JButton bClose;

private javax.swing.JButton bDelete;

private javax.swing.JButton bHitung;

private javax.swing.JButton bReset;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;

private javax.swing.JLabel jLabel7;

private javax.swing.JPanel jPanel1;

private javax.swing.JScrollPane jpesan;

private javax.swing.JTable tblpesan;

private javax.swing.JTextField txthapus;

private javax.swing.JTextField txtorder;

private javax.swing.JTextField txttotalbayar;

// End of variables declaration

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s