Program Java : Membuat Menu Makanan pada Java

Beberapa hari lalu saya dan teman - teman disuruh bikin program Java untuk Membuat Menu Makanan pada Java awalnya saya bingung tapi oprek - oprek diinternet eh dapat deh caranya.. berikut script javanya ... cekidot.


import javax.swing.JOptionPane;
public class Database extends javax.swing.JFrame {
public static int hargaSoto = 5000;
public static int hargaRawon = 6000;
public static int hargaBakso = 4000;
public static int hargaGudeg = 8000;


public Database() {
initComponents();
}


@SuppressWarnings("unchecked")
//
private void initComponents() {

cbSoto = new javax.swing.JCheckBox();
cbRawon = new javax.swing.JCheckBox();
cbBakso = new javax.swing.JCheckBox();
cbGudeg = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
tfSoto = new javax.swing.JTextField();
tfRawon = new javax.swing.JTextField();
tfBakso = new javax.swing.JTextField();
tfGudeg = new javax.swing.JTextField();
bHitung = new javax.swing.JButton();
bClear = new javax.swing.JButton();
tfTotal = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

cbSoto.setText("Soto : 5000");
cbSoto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbSotoActionPerformed(evt);
}
});

cbRawon.setText("Rawon : 6000");
cbRawon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbRawonActionPerformed(evt);
}
});

cbBakso.setText("Bakso : 4000");
cbBakso.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbBaksoActionPerformed(evt);
}
});

cbGudeg.setText("Gudeg : 8000");
cbGudeg.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbGudegActionPerformed(evt);
}
});

jLabel1.setText("Hitung : ");

bHitung.setText("Hitung");
bHitung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bHitungActionPerformed(evt);
}
});

bClear.setText("Clear");
bClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bClearActionPerformed(evt);
}
});

jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel2.setText("PROGRAM DEN KO");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(51, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cbSoto)
.addComponent(cbRawon)
.addComponent(cbBakso)
.addComponent(cbGudeg)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1)))
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tfTotal)
.addComponent(tfGudeg)
.addComponent(tfBakso)
.addComponent(tfRawon)
.addComponent(tfSoto, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(bClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bHitung)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(86, 86, 86)))
.addGap(42, 42, 42))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbSoto)
.addComponent(tfSoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbRawon)
.addComponent(tfRawon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbBakso)
.addComponent(tfBakso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbGudeg)
.addComponent(tfGudeg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bHitung))
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(bClear)
.addComponent(tfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}//


private void cbSotoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbSoto.isSelected() == true){
tfSoto.setEditable(true);
}
else {
tfSoto.setEditable(false);
tfSoto.setText("");
}
}

private void cbBaksoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbBakso.isSelected() == true){
tfBakso.setEditable(true);
}
else {
tfBakso.setEditable(false);
tfBakso.setText("");
}
}

private void cbRawonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbRawon.isSelected() == true){
tfRawon.setEditable(true);
}
else {
tfRawon.setEditable(false);
tfRawon.setText("");
}
}

private void cbGudegActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbGudeg.isSelected() == true){
tfGudeg.setEditable(true);
}
else {
tfGudeg.setEditable(false);
tfGudeg.setText("");
}
}

private void bHitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int totalHarga = 0;

if (cbSoto.isSelected()){
if(!tfSoto.getText().equalsIgnoreCase("")){
totalHarga+=Integer.parseInt(tfSoto.getText())* hargaSoto;
}else
JOptionPane.showMessageDialog(null,"Maaf Belum anda Terisi","Error", JOptionPane.ERROR_MESSAGE);
}
if(cbBakso.isSelected()){
if(!tfBakso.getText().equalsIgnoreCase("")){
totalHarga+=Integer.parseInt(tfBakso.getText())* hargaBakso;
}
else
JOptionPane.showMessageDialog(null, "Maaf Belum anda Isi","Error", JOptionPane.ERROR_MESSAGE);
}


if (cbRawon.isSelected()){
if(!tfRawon.getText().equalsIgnoreCase("")){
totalHarga+=Integer.parseInt(tfRawon.getText()) *hargaRawon;
}
else
JOptionPane.showMessageDialog(null,"Maaf belum Anda terisi","Error",JOptionPane.ERROR_MESSAGE);
}

if (cbGudeg.isSelected()){
if(!tfGudeg.getText().equalsIgnoreCase("")){
totalHarga+=Integer.parseInt(tfGudeg.getText())*hargaGudeg;
}
else
JOptionPane.showMessageDialog(null,"Maaf Belum Anda Isi", "Error",JOptionPane.ERROR_MESSAGE);
}
tfTotal.setText(""+totalHarga);
}

private void bClearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tfSoto.setText("");
tfBakso.setText("");
tfRawon.setText("");
tfGudeg.setText("");
tfTotal.setText("");
cbSoto.setSelected(false);
cbBakso.setSelected(false);
cbRawon.setSelected(false);
cbGudeg.setSelected(false);
tfSoto.setEditable(false);
tfBakso.setEditable(false);
tfRawon.setEditable(false);
tfGudeg.setEditable(false);
}


public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Database().setVisible(true);
}
});
}


// Variables declaration - do not modify
private javax.swing.JButton bClear;
private javax.swing.JButton bHitung;
private javax.swing.JCheckBox cbBakso;
private javax.swing.JCheckBox cbGudeg;
private javax.swing.JCheckBox cbRawon;
private javax.swing.JCheckBox cbSoto;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField tfBakso;
private javax.swing.JTextField tfGudeg;
private javax.swing.JTextField tfRawon;
private javax.swing.JTextField tfSoto;
private javax.swing.JTextField tfTotal;


}

Inilah tampilan Akhirnya..

Catatan : Sebelum code nya dibuat, sebelumnya bikin tampilan seperti gambar di atas dulu. dengan Swing GUI Form.


0 Responses to “Program Java : Membuat Menu Makanan pada Java”

Post a Comment