Selasa, 18 Juli 2017

Uas Alpro II, Reg C Modul 3

Program penjualan Kaca Mata menggunakan Java neat Beans
A.   Deskripsi Aplikasi
Kebanyakan orang menggunakan kacamata sebagai style maupun untuk menunjang penampilan agar lebih percaya diri. Terdapat banyak jenis frame kaca mata yang dapat digunakan sebagai style, seperti: frame kacamata aviator, frame kacamata cat eye, frame kacamata clubmaster, frame kacamata wayfarer, frame kacamata oversized, kacamata shield dan lain sebagainya. Kacamata telah menjadi tren di kalangan anak muda khususnya di Indonesia, hal ini yang yang bisa dimanfaatkan oleh para pebisnis untuk membuka bisnis penjualan kacamata. Jika ingin mendapatkan untuk yang besar, penjualan dapat dilakukan secara offline maupun online. Penjualan offline dapat dilakukan dengan menjual kacamata pada toko sedangkan penjualan secara online dapat memanfaatkan website toko online. Berbicara mengenai penjualan secara offline, terkadang pebisnis menggunakan software atau program untuk mendukung proses transaksi penjualan. Jika ingin mendapatkan untung yang besar, penjualan dapat dilakukan secara offline maupun online. Penjualan offline dapat dilakukan dengan menjual kacamata pada toko sedangkan penjualan secara online dapat memanfaatkan website toko online. Berbicara mengenai penjualan secara offline, terkadang pebisnis menggunakan software atau program untuk mendukung proses transaksi penjualan. Terinspirasi dari hal tersebut, Saya mencoba membuat sebuah program penjualan kacamata menggunakan Java NetBeans. Berikut ini penjelasan cara pembuatan program beserta scriptnya.

1. Jalankan software 
Anda dapat membuat program penjualan kacamata menggunakan software NetBeans. Jika software telah dijalankan, pilih File > New Project untuk membuat sebuah project baru seperti gambar berikut ini. 



2.Pada project baru biasanya otomatis terdapat class baru, namun jika ingin membuat class dengan cara klik kanan pada package > New > Java class dan beri nama ProgramPenjualanKacaMata. 
3.Selanjutnya pembuatan script pemrograman java pada class ProgramPenjualanKacaMata. 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.penjualan.kaca.mata;

/**
 *
 * @author Tetuko Sendleep
 */
public class ProgramPenjualanKacaMata {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Frame_penjualan_kaca_mata Laund = new Frame_penjualan_kaca_mata();
        Laund.setVisible(true);
    }
}

4.
Buat frame dengan cara klik kanan pada package > New > JFrame Form dengan nama Frame_penjualan_kaca_mata. Berikut ini contoh cara pembuatan frame baru.

Buat desain frame seperti contoh dibawah ini.
Buat script pemrograman java pada frame dengan cara klik kanan pada button Hitung > Events > Actions > ActionPerformed. 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.penjualan.kaca.mata;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @
author Tetuko Sendleep */public class Frame_penjualan_kaca_mata extends javax.swing.JFrame {
    /**
     * Creates new form Frame_penjualan_kaca_mata
     */
    public Frame_penjualan_kaca_mata() {
        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() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        panel_tempat_gambar = new javax.swing.JEditorPane();
        jLabel8 = new javax.swing.JLabel();
        Pilihan1 = new javax.swing.JRadioButton();
        Pilihan2 = new javax.swing.JRadioButton();
        Pilihan4 = new javax.swing.JRadioButton();
        Pilihan3 = new javax.swing.JRadioButton();
        txtSatuan = new javax.swing.JTextField();
        txtNama = new javax.swing.JTextField();
        txtJumlah = new javax.swing.JTextField();
        btnHitung = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtBayar = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        btnHapus = new javax.swing.JButton();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane1.setViewportView(panel_tempat_gambar);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Pilihan Kaca Mata");

        Pilihan1.setText("Pilihan 1");
        Pilihan1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan1ActionPerformed(evt);
            }
        });

        Pilihan2.setText("Pilihan 2");
        Pilihan2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan2ActionPerformed(evt);
            }
        });

        Pilihan4.setText("Pilihan 4");
        Pilihan4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan4ActionPerformed(evt);
            }
        });

        Pilihan3.setText("Pilihan 3");
        Pilihan3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan3ActionPerformed(evt);
            }
        });

        txtSatuan.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        txtNama.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        txtJumlah.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        btnHitung.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnHitung.setText("Hitung");
        btnHitung.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHitungActionPerformed(evt);
            }
        });

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

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Nama Kaca Mata");

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

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Jumlah Pembelian");

        txtBayar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Program Sederhana Penjualan Kaca Mata");

        btnHapus.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(50, 50, 50)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtJumlah, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                                            .addComponent(txtBayar)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel8))
                                        .addGap(53, 53, 53)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtNama)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(Pilihan3)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(Pilihan4))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(Pilihan1)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(Pilihan2)))
                                                .addGap(73, 73, 73))
                                            .addComponent(txtSatuan)))))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnHitung)
                                .addGap(14, 14, 14)
                                .addComponent(btnHapus)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(92, 92, 92)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel1)
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(Pilihan1)
                            .addComponent(Pilihan2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Pilihan3)
                            .addComponent(Pilihan4))
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtSatuan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnHitung)
                            .addComponent(btnHapus)))
                    .addComponent(jScrollPane1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtBayar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 30, Short.MAX_VALUE))
        );

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

    private void Pilihan1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
//        // TODO add your handling code here:
        txtSatuan.setText("39000");
        txtNama.setText("Women Outdoor Sunglasses");
        JLabel label_gambar = new JLabel(new ImageIcon("src/gambar/Women Outdoor Sunglasses.jpg"));

        //x,y,lebar, tinggi
        label_gambar.setBounds(2, 2, 2, 2);
        label_gambar.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

    private void Pilihan2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtSatuan.setText("360000");
        txtNama.setText("Spy Eyewear Glasses");
         JLabel label_gambar1 = new JLabel(new ImageIcon("src/gambar/Spy Eyewear Glasses.jpg"));

        //x,y,lebar, tinggi
        label_gambar1.setBounds(2, 2, 2, 2);
        label_gambar1.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar1);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

    private void Pilihan4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtSatuan.setText("1800000");
        txtNama.setText("Nike 7872AF Kacamata");
         JLabel label_gambar2 = new JLabel (new ImageIcon("src/gambar/Nike 7872AF Kacamata.jpg"));

        //x,y,lebar, tinggi
        label_gambar2.setBounds(2, 2, 2, 2);
        label_gambar2.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar2);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

    private void Pilihan3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtSatuan.setText("3550000");
        txtNama.setText("Porsche Design P'8566");
         JLabel label_gambar3 = new JLabel(new ImageIcon("src/gambar/Porsche Design P'8566.jpg"));
          
        //x,y,lebar, tinggi
        label_gambar3.setBounds(2, 2, 2, 2);
        label_gambar3.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar3);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

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

        int a = Integer.parseInt(txtSatuan.getText());
        int b = Integer.parseInt(txtJumlah.getText());
        int hasilnya = a * b;
        txtBayar.setText("" + hasilnya);


    }                                        

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtNama.setText("");
        txtJumlah.setText("");
        txtSatuan.setText("");
        txtBayar.setText("");
        Pilihan1.setSelected(false);
        Pilihan2.setSelected(false);
        Pilihan3.setSelected(false);
        Pilihan4.setSelected(false);
        panel_tempat_gambar.removeAll();
    }                                       

    /**
     * @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(Frame_penjualan_kaca_mata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_kaca_mata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_kaca_mata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_kaca_mata.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 Frame_penjualan_kaca_mata().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JRadioButton Pilihan1;
    private javax.swing.JRadioButton Pilihan2;
    private javax.swing.JRadioButton Pilihan3;
    private javax.swing.JRadioButton Pilihan4;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnHitung;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JEditorPane panel_tempat_gambar;
    private javax.swing.JTextField txtBayar;
    private javax.swing.JTextField txtJumlah;
    private javax.swing.JTextField txtNama;
    private javax.swing.JTextField txtSatuan;
    // End of variables declaration                  
}

 


B.Komponen:
  1. pilihan kacamata
  2. harga satuan
  3. nama kacamata
  4. jumlah pembelian
  5. total bayar
C.Flowchart
 
D.Source Code
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.penjualan.kaca.mata;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author Tetuko Sendleep
 */
public class Frame_penjualan_kaca_mata extends javax.swing.JFrame {
    /**
     * Creates new form Frame_penjualan_kaca_mata
     */
    public Frame_penjualan_kaca_mata() {
        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() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        panel_tempat_gambar = new javax.swing.JEditorPane();
        jLabel8 = new javax.swing.JLabel();
        Pilihan1 = new javax.swing.JRadioButton();
        Pilihan2 = new javax.swing.JRadioButton();
        Pilihan4 = new javax.swing.JRadioButton();
        Pilihan3 = new javax.swing.JRadioButton();
        txtSatuan = new javax.swing.JTextField();
        txtNama = new javax.swing.JTextField();
        txtJumlah = new javax.swing.JTextField();
        btnHitung = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtBayar = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        btnHapus = new javax.swing.JButton();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane1.setViewportView(panel_tempat_gambar);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Pilihan Kaca Mata");

        Pilihan1.setText("Pilihan 1");
        Pilihan1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan1ActionPerformed(evt);
            }
        });

        Pilihan2.setText("Pilihan 2");
        Pilihan2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan2ActionPerformed(evt);
            }
        });

        Pilihan4.setText("Pilihan 4");
        Pilihan4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan4ActionPerformed(evt);
            }
        });

        Pilihan3.setText("Pilihan 3");
        Pilihan3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pilihan3ActionPerformed(evt);
            }
        });

        txtSatuan.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        txtNama.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        txtJumlah.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        btnHitung.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnHitung.setText("Hitung");
        btnHitung.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHitungActionPerformed(evt);
            }
        });

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

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Nama Kaca Mata");

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

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Jumlah Pembelian");

        txtBayar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Program Sederhana Penjualan Kaca Mata");

        btnHapus.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(50, 50, 50)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtJumlah, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                                            .addComponent(txtBayar)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel8))
                                        .addGap(53, 53, 53)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtNama)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(Pilihan3)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(Pilihan4))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(Pilihan1)
                                                        .addGap(18, 18, 18)
                                                        .addComponent(Pilihan2)))
                                                .addGap(73, 73, 73))
                                            .addComponent(txtSatuan)))))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnHitung)
                                .addGap(14, 14, 14)
                                .addComponent(btnHapus)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(92, 92, 92)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel1)
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(Pilihan1)
                            .addComponent(Pilihan2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Pilihan3)
                            .addComponent(Pilihan4))
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtSatuan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnHitung)
                            .addComponent(btnHapus)))
                    .addComponent(jScrollPane1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtBayar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 30, Short.MAX_VALUE))
        );

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

    private void Pilihan1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
//        // TODO add your handling code here:
        txtSatuan.setText("39000");
        txtNama.setText("Women Outdoor Sunglasses");
        JLabel label_gambar = new JLabel(new ImageIcon("src/gambar/Women Outdoor Sunglasses.jpg"));

        //x,y,lebar, tinggi
        label_gambar.setBounds(2, 2, 2, 2);
        label_gambar.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

    private void Pilihan2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtSatuan.setText("360000");
        txtNama.setText("Spy Eyewear Glasses");
         JLabel label_gambar1 = new JLabel(new ImageIcon("src/gambar/Spy Eyewear Glasses.jpg"));

        //x,y,lebar, tinggi
        label_gambar1.setBounds(2, 2, 2, 2);
        label_gambar1.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar1);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

    private void Pilihan4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtSatuan.setText("1800000");
        txtNama.setText("Nike 7872AF Kacamata");
         JLabel label_gambar2 = new JLabel (new ImageIcon("src/gambar/Nike 7872AF Kacamata.jpg"));

        //x,y,lebar, tinggi
        label_gambar2.setBounds(2, 2, 2, 2);
        label_gambar2.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar2);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

    private void Pilihan3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtSatuan.setText("3550000");
        txtNama.setText("Porsche Design P'8566");
         JLabel label_gambar3 = new JLabel(new ImageIcon("src/gambar/Porsche Design P'8566.jpg"));
          
        //x,y,lebar, tinggi
        label_gambar3.setBounds(2, 2, 2, 2);
        label_gambar3.setSize(200, 200);
        panel_tempat_gambar.add(label_gambar3);
        panel_tempat_gambar.revalidate();
        panel_tempat_gambar.repaint();
    }                                       

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

        int a = Integer.parseInt(txtSatuan.getText());
        int b = Integer.parseInt(txtJumlah.getText());
        int hasilnya = a * b;
        txtBayar.setText("" + hasilnya);


    }                                        

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtNama.setText("");
        txtJumlah.setText("");
        txtSatuan.setText("");
        txtBayar.setText("");
        Pilihan1.setSelected(false);
        Pilihan2.setSelected(false);
        Pilihan3.setSelected(false);
        Pilihan4.setSelected(false);
        panel_tempat_gambar.removeAll();
    }                                       

    /**
     * @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(Frame_penjualan_kaca_mata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_kaca_mata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_kaca_mata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_kaca_mata.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 Frame_penjualan_kaca_mata().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JRadioButton Pilihan1;
    private javax.swing.JRadioButton Pilihan2;
    private javax.swing.JRadioButton Pilihan3;
    private javax.swing.JRadioButton Pilihan4;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnHitung;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JEditorPane panel_tempat_gambar;
    private javax.swing.JTextField txtBayar;
    private javax.swing.JTextField txtJumlah;
    private javax.swing.JTextField txtNama;
    private javax.swing.JTextField txtSatuan;
    // End of variables declaration                  
}

Lihat hasil 
Jalankan hasil program penjualan kacamata dengan memilih Run Main Project(F6) atau Pilih Project > Klik kanan > Run. Pada program tersebut, Anda dapat memilih no pilihan kaca mata dan input jumlah pembelian. Pilih button Hitung maka akan muncul total biaya yang harus dibayar.