Ya Teman - Teman Kali ini saya akan memberikan contoh tentang Aplikasi Menu Makanan java sederhana yang pernah saya buat dengan menggunakan bahasa pemograman Java. Mungkin bagi temen - temen yang ingin mengembangkan project saya ini menjadi lebih baik lagi silakan saja.
classMenuMakanan
package menumakanan;
public class MenuMakanan {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
UIMenuMakanan menu = new UIMenuMakanan();
menu.setVisible(true);
}
}
public class MenuMakanan {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
UIMenuMakanan menu = new UIMenuMakanan();
menu.setVisible(true);
}
}
Class ModelPaket
package menumakanan;
public class ModelPaket {
private String namaPaket;
private String isiPaket;
private float harga;
public ModelPaket(){
}
public ModelPaket(String namaPaket, String isiPaket, float harga){
this.namaPaket=namaPaket;
this.isiPaket=isiPaket;
this.harga=harga;
}
/**
* @return the namaPaket
*/
public String getNamaPaket() {
return namaPaket;
}
/**
* @param namaPaket the namaPaket to set
*/
public void setNamaPaket(String namaPaket) {
this.namaPaket = namaPaket;
}
/**
* @return the isiPaket
*/
public String getIsiPaket() {
return isiPaket;
}
/**
* @param isiPaket the isiPaket to set
*/
public void setIsiPaket(String isiPaket) {
this.isiPaket = isiPaket;
}
/**
* @return the harga
*/
public float getHarga() {
return harga;
}
/**
* @param harga the harga to set
*/
public void setHarga(float harga) {
this.harga = harga;
}
@Override
public String toString() {
return namaPaket;
}
}
public class ModelPaket {
private String namaPaket;
private String isiPaket;
private float harga;
public ModelPaket(){
}
public ModelPaket(String namaPaket, String isiPaket, float harga){
this.namaPaket=namaPaket;
this.isiPaket=isiPaket;
this.harga=harga;
}
/**
* @return the namaPaket
*/
public String getNamaPaket() {
return namaPaket;
}
/**
* @param namaPaket the namaPaket to set
*/
public void setNamaPaket(String namaPaket) {
this.namaPaket = namaPaket;
}
/**
* @return the isiPaket
*/
public String getIsiPaket() {
return isiPaket;
}
/**
* @param isiPaket the isiPaket to set
*/
public void setIsiPaket(String isiPaket) {
this.isiPaket = isiPaket;
}
/**
* @return the harga
*/
public float getHarga() {
return harga;
}
/**
* @param harga the harga to set
*/
public void setHarga(float harga) {
this.harga = harga;
}
@Override
public String toString() {
return namaPaket;
}
}
Class UIMenuMakanan
package menumakanan;
public class UIMenuMakanan extends javax.swing.JFrame {
public UIMenuMakanan() {
initComponents();
ModelPaket paket1 = new ModelPaket("Paket A", "Nasi + Ayam Bakar + Teh Es", 18000);
ModelPaket paket2 =new ModelPaket("Paket B", "Nasi + Ikan Goreng + Teh Botol", 15000);
ModelPaket paket3=new ModelPaket("Paket C", "Nasi Uduk + Pecel Lele + Air Mineral", 28000);
cboPaket.addItem(paket1);
cboPaket.addItem(paket2);
cboPaket.addItem(paket3);
//cboPaket.setSelectedIndex(1);
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
cboPaket = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
lblIsiPaket = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
lblHarga = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("Paket");
cboPaket.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
cboPaket.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cboPaketActionPerformed(evt);
}
});
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Isi Paket");
lblIsiPaket.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lblIsiPaket.setText("IsiPaket");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setText("Harga");
lblHarga.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lblHarga.setText("Harga");
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel4.setText("Program Memilih Menu Makanan");
jLabel5.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N
jLabel5.setText("WARTEG GAGAKREATIF");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cboPaket, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblIsiPaket, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel4)))
.addGroup(layout.createSequentialGroup()
.addGap(96, 96, 96)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(20, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(jLabel5)
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cboPaket, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(lblIsiPaket))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(lblHarga))
.addContainerGap(71, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void cboPaketActionPerformed(java.awt.event.ActionEvent evt) {
ModelPaket paket = (ModelPaket)cboPaket.getSelectedItem();
lblIsiPaket.setText(paket.getIsiPaket());
lblHarga.setText(String.valueOf(paket.getHarga()));
}
/**
* @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(UIMenuMakanan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(UIMenuMakanan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(UIMenuMakanan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(UIMenuMakanan.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 UIMenuMakanan().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox cboPaket;
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 lblHarga;
private javax.swing.JLabel lblIsiPaket;
// End of variables declaration
}
Dan Berikut Ini Design Tampilanya Gan :
Jalankan Program :
Langkah terakhir adalah menjalankan program dengan memilih Run Main Project(F6) atau Pilih Project > Klik kanan > Run. Selanjutnya akan muncul program yang telah Anda buat. Anda dapat memilih paket makanan yang anda inginkan ya boss...hehehehe :)
Langkah terakhir adalah menjalankan program dengan memilih Run Main Project(F6) atau Pilih Project > Klik kanan > Run. Selanjutnya akan muncul program yang telah Anda buat. Anda dapat memilih paket makanan yang anda inginkan ya boss...hehehehe :)
Terimakasih telah mengunjungi blog saya ini.
Pengunjung yg baik selalu ninggalin jejak :)
Salam Wani Sinau!
Tidak ada komentar:
Posting Komentar