Membuat Menu Pesanan Makanan dengan Java

Kesempatan kali ini saya akan memberi tutorial tentang cara membuat menu pesanan makanan menggunakan program Java.Di bawah ini saya langsung cantumkan seluruh sourcodenya sampai terbentuk GUI interface java dengan mengaplikasikan menu makanan selesai. Mungkin ada yang bisa membuat lebih bagus dari pada saya.Maklum lah saya membuat asal jadi dan mudah dipahami hehehe Ngeles.Salah satu contohnya adalah berikut.



import javax.swing.JOptionPane;
    public data2() {
        initComponents();
    }
    @SuppressWarnings("unchecked")
    //                           
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        q = new javax.swing.JCheckBox();
        e = new javax.swing.JCheckBox();
        w = new javax.swing.JCheckBox();
        r = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        a = new javax.swing.JTextField();
        s = new javax.swing.JTextField();
        d = new javax.swing.JTextField();
        f = new javax.swing.JTextField();
        g = new javax.swing.JTextField();
        hitung = new javax.swing.JButton();
        clear = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Menu Istimewa");

        q.setText("Soto : 5000");
        q.setActionCommand("Rawon : ");
        q.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                qActionPerformed(evt);
            }
        });

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

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

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

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Total Harga");

        a.setEditable(false);
        s.setEditable(false);
        d.setEditable(false);
        f.setEditable(false);
        g.setEditable(false);

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

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(jLabel1)
                        .addContainerGap(114, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(r)
                            .addComponent(e)
                            .addComponent(w)
                            .addComponent(q)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(jLabel2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(s, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
                                .addComponent(d, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(a)
                                .addComponent(f))
                            .addComponent(g, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(46, 46, 46)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(hitung)
                            .addComponent(clear))
                        .addGap(22, 22, 22))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(hitung)
                        .addGap(18, 18, 18)
                        .addComponent(clear)
                        .addGap(27, 27, 27)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(q))
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(s, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(w))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(d, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(e))
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(f, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(r))
                        .addGap(43, 43, 43)
                        .addComponent(g, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(61, Short.MAX_VALUE))
        );

        pack();
    }//                         

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

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

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

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

    private void hitungActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        int total=0;
        int jumlahsoto,biayasoto,jumlahrawon,biayarawon;
        int jumlahbakso,biayabakso,jumlahgudeg,biayagudeg;
        
        try{
            if(q.isSelected())
            {
                String soto=a.getText();
                jumlahsoto=Integer.parseInt(soto);
                biayasoto=jumlahsoto*5000;
                total=total+biayasoto;
            }
            if(w.isSelected())
            {
                String rawon=s.getText();
                jumlahrawon=Integer.parseInt(rawon);
                biayarawon=jumlahrawon*6000;
                total=total+biayarawon;
            }
            if(e.isSelected())
            {
                String bakso=d.getText();
                jumlahbakso=Integer.parseInt(bakso);
                biayabakso=jumlahbakso*4000;
                total=total+biayabakso;
            }
            if(r.isSelected())
            {
                String gudeg=f.getText();
                jumlahgudeg=Integer.parseInt(gudeg);
                biayagudeg=jumlahgudeg*8000;
                total=total+biayagudeg;
            }
            g.setText(""+total);
        }catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null,"Jumlah Pesanan Belum Terisi");
        }
        
    }                                      

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        a.setText("");
        a.setEditable(false);
        s.setText("");
        s.setEditable(false);
        d.setText("");
        d.setEditable(false);
        f.setText("");
        f.setEditable(false);
        g.setText(" ");
    }                                     

        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(data2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(data2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(data2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(data2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
      
  java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new data2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JTextField a;
    private javax.swing.JButton clear;
    private javax.swing.JTextField d;
    private javax.swing.JCheckBox e;
    private javax.swing.JTextField f;
    private javax.swing.JTextField g;
    private javax.swing.JButton hitung;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JCheckBox q;
    private javax.swing.JCheckBox r;
    private javax.swing.JTextField s;
    private javax.swing.JCheckBox w;
    // End of variables declaration                   
}
Semoga tutorial saya bermanfaat dan jangan lupa dibagi ya. SEMANGAT MEMBARA

Tidak ada komentar