Minggu, 13 Januari 2019

Program Aplikasi Bakso Makenull


Nama : Pujiyanti Purnamasari
Kelas : 01TPLE003
Ruang: V.507 
Semester : 1 (ganjil)
Regular : C
Jurusan : Teknik Informatika (IT)
Matkul: Algoritma Pemograman 1


Cara Membuat Aplikasi Sederhana Menggunakan Jframe java netbeants

Aplikasi pada desain Jframe kali ini menggunakan control tiextfield, check box, button, menu bar, dan jCheckbox,( jika tidak di klik , kita tidak bisa mengisi textfield) dengan membuat aplikasi perhitungan jumlah total BAKSO MAKENULL.

Untuk lebih mudah dipahami, langsung saja kita akan membuat sebuah program yang sederhana seperti screnshoot dibawah ini: 

 Berikut Desain jFrame baskso makenull





 Cooding Jframe Bakso Makenull




 /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author HP
 */
public class baksoblts extends javax.swing.JFrame {

    /**
     * Creates new form baksoblts
     */
    public baksoblts() {
        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() {

        blts = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox2BAKSOTELUR = new javax.swing.JTextField();
        jCheckBox1BAKSOURAT = new javax.swing.JTextField();
        jCheckBox4MIEAYAMBAKSO = new javax.swing.JTextField();
        jCheckBox3MIEAYAM = new javax.swing.JTextField();
        hitung = new javax.swing.JButton();
        hapus = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        TOTALHARGA = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        blts.setText("Bakso Makenull");

        jCheckBox1.setText("BAKSO URAT @ Rp. 8000");

        jCheckBox2.setText("MIE AYAM BAKSO @ Rp. 8000");

        jCheckBox3.setText("BAKSO TELUR @ Rp. 8000");
        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        jCheckBox4.setText("MIE AYAM @ Rp. 6000");
        jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox4ActionPerformed(evt);
            }
        });

        jCheckBox2BAKSOTELUR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2BAKSOTELURActionPerformed(evt);
            }
        });

        jCheckBox1BAKSOURAT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1BAKSOURATActionPerformed(evt);
            }
        });

        jCheckBox4MIEAYAMBAKSO.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox4MIEAYAMBAKSOActionPerformed(evt);
            }
        });

        jCheckBox3MIEAYAM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3MIEAYAMActionPerformed(evt);
            }
        });

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

        hapus.setText("HAPUS");
        hapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hapusActionPerformed(evt);
            }
        });

        jLabel1.setText("JUMLAH HARGA");
        jLabel1.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
                jLabel1AncestorRemoved(evt);
            }
        });

        TOTALHARGA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TOTALHARGAActionPerformed(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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jCheckBox2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jCheckBox4MIEAYAMBAKSO, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckBox3)
                                    .addComponent(jCheckBox4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jCheckBox2BAKSOTELUR)
                                    .addComponent(jCheckBox3MIEAYAM, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .addComponent(jCheckBox1BAKSOURAT)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(128, 128, 128)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(hitung)
                                    .addComponent(jLabel1))
                                .addGap(42, 42, 42)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(hapus)
                                        .addGap(0, 51, Short.MAX_VALUE))
                                    .addComponent(TOTALHARGA))))
                        .addGap(31, 31, 31))))
            .addGroup(layout.createSequentialGroup()
                .addGap(171, 171, 171)
                .addComponent(blts)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(blts)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBox3)
                            .addComponent(jCheckBox2BAKSOTELUR, 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(jCheckBox4)
                            .addComponent(jCheckBox3MIEAYAM, 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.LEADING)
                            .addComponent(jCheckBox2)
                            .addComponent(jCheckBox4MIEAYAMBAKSO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jCheckBox1BAKSOURAT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hitung)
                    .addComponent(hapus))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(TOTALHARGA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29))
        );

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

    private void hapusActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        jCheckBox1BAKSOURAT.setEditable(false);
        jCheckBox1BAKSOURAT.setText("");
      
        jCheckBox2BAKSOTELUR.setEditable(false);
        jCheckBox2BAKSOTELUR.setText("");
      
        jCheckBox3MIEAYAM.setEditable(false);
        jCheckBox3MIEAYAM.setText("");
      
        jCheckBox4MIEAYAMBAKSO.setEditable(false);
        jCheckBox4MIEAYAMBAKSO.setText("");
      
        TOTALHARGA.setText("");
      
    }                                   

    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

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

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

    }                                                 

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

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

    private void hitungActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        int total=0;
    if(jCheckBox1.isSelected ()){
        String BU=jCheckBox1.getText();
        int jumlahBU=Integer.parseInt(BU);
        int HargaBaksoUrat=jumlahBU*8000;
        total = total+ HargaBaksoUrat;
    }
  
    if(jCheckBox2.isSelected ()){
        String BU=jCheckBox2.getText();
        int jumlahBT=Integer.parseInt(BU);
        int hargaBT=jumlahBT*10000;
        total = total+ hargaBT;
    }
  
      if(jCheckBox3.isSelected ()){
        String BU=jCheckBox3.getText();
        int jumlahMA=Integer.parseInt(BU);
        int hargaMA=jumlahMA*10000;
        total = total+ hargaMA;
    }
    
      if(jCheckBox4.isSelected()){
        String BU=jCheckBox4.getText();
        int jumlahMAB=Integer.parseInt(BU);
        int hargaMAB=jumlahMAB*15000;
        total = total+ hargaMAB;
      
        TOTALHARGA.setText("");
    }                                    

    private void jLabel1AncestorRemoved(javax.swing.event.AncestorEvent evt) {                                      

    }                                     

    private void TOTALHARGAActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        TOTALHARGA.setText("");
    }                                        

    private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    /**
     * @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(baksoblts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(baksoblts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(baksoblts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(baksoblts.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 baksoblts().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                   
    private javax.swing.JTextField TOTALHARGA;
    private javax.swing.JLabel blts;
    private javax.swing.JButton hapus;
    private javax.swing.JButton hitung;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JTextField jCheckBox1BAKSOURAT;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JTextField jCheckBox2BAKSOTELUR;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JTextField jCheckBox3MIEAYAM;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JTextField jCheckBox4MIEAYAMBAKSO;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration                 
}


Tidak ada komentar:

Posting Komentar