Tadi pagi saya sudah memposting Belajar java menggunakan Netbeans dengan program sederhana, disini saya akan memberikan tambahan program sederhana GUI yaitu program menu makanan.. semoga dapat membantu kawan-kawan eka blog belajar.. cara masih sama seperti postingan saya sebelumnya, jika belum paham silahkan baca
"Mari Belajar Java Menggunakan Netbeans"
Silahkan copy dan paste codingan dibawah ini ke project yg sudah dibuat..
coding menu makanan program java menggunakan netbeans :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Database.java
*
* Created on Dec 3, 2011, 9:57:06 PM
*/
package MyPrj;
/**
*
* @author ekaIlaika
*/
public class Database extends javax.swing.JFrame {
/** Creates new form Database */
public Database() {
initComponents();
}
private String str = " ";
private int a, b, c, d;
/** 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")
//
private void initComponents() {
cbBakso = new javax.swing.JCheckBox();
cbSomay = new javax.swing.JCheckBox();
cbMieAyam = new javax.swing.JCheckBox();
cbNasiGoreng = new javax.swing.JCheckBox();
tfa = new javax.swing.JTextField();
tfb = new javax.swing.JTextField();
tfc = new javax.swing.JTextField();
tfd = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
lbHit = new javax.swing.JLabel();
bHitung = new javax.swing.JButton();
tfHasil = new javax.swing.JTextField();
bClear = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
cbBakso.setText("Bakso : 6000");
cbBakso.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbBaksoActionPerformed(evt);
}
});
cbSomay.setText("Somay : 6000");
cbSomay.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbSomayActionPerformed(evt);
}
});
cbMieAyam.setText("Mie Ayam : 6500");
cbMieAyam.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbMieAyamActionPerformed(evt);
}
});
cbNasiGoreng.setText("Nasi Goreng : 8000");
cbNasiGoreng.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbNasiGorengActionPerformed(evt);
}
});
tfa.setEditable(false);
tfa.setText("0");
tfa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfaActionPerformed(evt);
}
});
tfb.setEditable(false);
tfb.setText("0");
tfc.setEditable(false);
tfc.setText("0");
tfc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfcActionPerformed(evt);
}
});
tfd.setEditable(false);
tfd.setText("0");
jLabel1.setFont(new java.awt.Font("Jokerman", 1, 14)); // NOI18N
jLabel1.setText("MENU MAKANAN");
lbHit.setText("Total yang harus dibayar :");
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.setText("Rp.");
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(150, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(104, 104, 104))
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cbMieAyam)
.addComponent(cbNasiGoreng)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(cbBakso)
.addComponent(cbSomay))
.addGroup(layout.createSequentialGroup()
.addComponent(lbHit, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tfHasil)
.addComponent(tfd)
.addComponent(tfc)
.addComponent(tfb)
.addComponent(tfa, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(bHitung)
.addComponent(bClear))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cbBakso))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cbSomay))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cbMieAyam))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cbNasiGoreng)
.addComponent(bHitung))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbHit, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfHasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bClear)
.addComponent(jLabel2))
.addContainerGap(60, Short.MAX_VALUE))
);
pack();
}//
private void tfcActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cbBaksoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbBakso.isSelected()==true){
tfa.setEditable(true);
}
else{
tfa.setEditable(false);
tfa.setText("0");
}
}
private void bHitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a = Integer.parseInt(tfa.getText());
b = Integer.parseInt(tfb.getText());
c = Integer.parseInt(tfc.getText());
d = Integer.parseInt(tfd.getText());
int hasil = (a*6000)+(b*6000)+(c*6500)+(d*8000);
tfHasil.setText(str + hasil);
}
private void cbSomayActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbSomay.isSelected()==true){
tfb.setEditable(true);
}
else{
tfb.setEditable(false);
tfb.setText("0");
}
}
private void cbMieAyamActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbMieAyam.isSelected()==true){
tfc.setEditable(true);
}
else{
tfc.setEditable(false);
tfc.setText("0");
}
}
private void cbNasiGorengActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (cbNasiGoreng.isSelected()==true){
tfd.setEditable(true);
}
else{
tfd.setEditable(false);
tfd.setText("0");
}
}
private void tfaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void bClearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (bClear.isSelected()==true){
tfHasil.setEditable(false);
}
else{
tfHasil.setEditable(true);
tfHasil.setText("0");
}
}
/**
* @param args the command line arguments
*/
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 cbMieAyam;
private javax.swing.JCheckBox cbNasiGoreng;
private javax.swing.JCheckBox cbSomay;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lbHit;
private javax.swing.JTextField tfHasil;
private javax.swing.JTextField tfa;
private javax.swing.JTextField tfb;
private javax.swing.JTextField tfc;
private javax.swing.JTextField tfd;
// End of variables declaration
}
PENAMPAKANNYA :
Gimana kawan? seru kan? tertarik untuk mempelajari pemrograman java mengunakan netbeans??
semoga bermanfaat, silahkan komentar jika ingin bertanya ..
0 comments:
Post a Comment