Selasa, 20 Juni 2017

Pemrograman sederhana Penjualan Air Mineral

Program Penjualan Air Mineral Menggunakan Java NetBeans



Descripsi: Setiap orang pasti membutuhkan air minum untuk dapat bertahan hidup. Bila tidak mengkonsumsi air yang cukup dapat menyebabkan Kita mudah terserang penyakit. Untuk itu, konsumsi air putih minimal 8 gelas atau 2 liter perhari. Setiap hari permintaan air minum tidak pernah berhenti, bahkan di daerah tertentu sering terjadi krisis stok air. Hal ini menandakan bahwa air minum sangat penting karena setiap orang membutuhkan air minum. Hal ini yang menyebabkan banyak produsen air minum memproduksi air kemasan dengan berbagai ukuran mulai dari 240 ml hingga 19 Liter. Air kemasan atau air mineral dapat Kita temukan pada super market, minimarket hingga warung. Bila membuka bisnis penjualan air mineral tentu keuntungan akan besar karena banyak permintaan air mineral. Berbicara mengenai penjualan air mineral, Kami mencoba membuat sebuah program sederhana untuk penjualan air mineral menggunakan Java NetBeans. Berikut ini penjelasan cara pembuatan program tersebut:



2. Komponen
  • Merk Air Mineral
  • ukuran
  • Harga satuan 
  • Jumlah Pembelian
  • Total Bayar

 4. Sourch Code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package penjualan.air.mineral;

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

/**
 *
 * @tetuko dwi cahyo
 */
public class Frame_penjualan_air_mineral extends javax.swing.JFrame {
    /**
     * Creates new form Frame_penjualan_air_mineral
     */
    public Frame_penjualan_air_mineral() {
        initComponents();
       
        cboMerk.addItem("Aqua");
        cboMerk.addItem("Club");
        cboMerk.addItem("Vit");
        cboMerk.addItem("Oasis");
       
    }

    /**
     * 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() {

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

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

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

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

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

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

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

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

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

        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);
            }
        });

        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);
            }
        });

        jScrollPane1.setViewportView(panel_tempat_gambar);

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

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

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

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Merk Air Mineral");

        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()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(84, 84, 84))
                    .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.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel8)
                                            .addComponent(jLabel2)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(49, 49, 49))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtJumlah)
                                    .addComponent(txtSatuan)
                                    .addComponent(cboMerk, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(txtBayar, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(Pilihan3)
                                            .addComponent(Pilihan1))
                                        .addGap(24, 24, 24)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(Pilihan2)
                                            .addComponent(Pilihan4)))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(btnHitung)
                                .addGap(14, 14, 14)
                                .addComponent(btnHapus)))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 16, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(cboMerk, 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(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(txtSatuan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .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))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnHitung)
                            .addComponent(btnHapus)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
                .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(32, 32, 32))
        );

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

    private void Pilihan1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
//        // TODO add your handling code here:
        txtSatuan.setText("55000");
        JLabel label_gambar = new JLabel(new ImageIcon("src/gambar/Air mineral.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("4500");
        JLabel label_gambar1 = new JLabel(new ImageIcon("src/gambar/Air mineral3.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("500");
        JLabel label_gambar2 = new JLabel(new ImageIcon("src/gambar/Air mineral4.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("1500");
        JLabel label_gambar3 = new JLabel(new ImageIcon("src/gambar/Air mineral2.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("Rp. " + hasilnya);
          

    }                                        

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        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_air_mineral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_air_mineral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_air_mineral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frame_penjualan_air_mineral.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_air_mineral().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.JComboBox cboMerk;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    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 txtSatuan;
    // End of variables declaration                  
}

5. hasil Run