distributor

/*
 * 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.
 */
package nmMaster;

import Class.classkoneksi;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;

/**
 *
 * @author RPL
 */
public class Distributor extends javax.swing.JFrame {
    private String namaDistributor;
    private String alamatDistributor;
    private String teleponDistributor;
    private boolean update = false;
    /**
     * Creates new form Distributor
     */
    public Distributor() {
        setUndecorated(true);
        getRootPane().setWindowDecorationStyle(JRootPane.NONE);
        initComponents();
        this.setLocationRelativeTo(this);
    }

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

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tNama = new javax.swing.JTextField();
        tAlamat = new javax.swing.JTextField();
        tTelepon = new javax.swing.JTextField();
        btnSimpan = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 102)), "Distributor"));

        jLabel2.setText("Nama Distributor");

        jLabel3.setText("Alamat");

        jLabel4.setText("Telepon");

        btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900179_floppy_disk_save.png"))); // NOI18N
        btnSimpan.setText("SIMPAN");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900274_ic_cancel_48px.png"))); // NOI18N
        jButton2.setText("BATAL");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
        jButton3.setText("KELUAR");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tNama, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                            .addComponent(tAlamat)
                            .addComponent(tTelepon)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(btnSimpan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(tAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSimpan)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        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()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                       
public void bersih(){
tNama.setText("");
tAlamat.setText("");
tTelepon.setText("");
}

    private void pushData(){
        tNama.setText(this.getNamaDistributor());
        tAlamat.setText(this.getAlamatDistributor());
        tTelepon.setText(this.getTeleponDistributor());
    }
   
    private void updateData() {
        String nama = tNama.getText();
        String alamat = tAlamat.getText();
        String telepon = tTelepon.getText();
        String SQL = "UPDATE distributor set nama_distributor = '"+nama+"',alamat = '"+alamat+"',telepon = '"+telepon+"' where nama_distributor='"+
                this.getNamaDistributor()+"'";
        int status = classkoneksi.execute(SQL);
        if(status>0){
            JOptionPane.showMessageDialog(this, "data berhasil diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
        }else{
            JOptionPane.showMessageDialog(this, "data gagal diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
        }
    }
   
    private void simpan(){
        if ("".equals(tNama.getText()) || "".equals(tAlamat.getText()) || "".equals(tTelepon.getText())) {
            JOptionPane.showMessageDialog(this, "Harap Lengkapi Data", "Eror", JOptionPane.WARNING_MESSAGE);
        } else {
            String SQL = "INSERT INTO distributor (nama_distributor,alamat,telepon)"
                    + "VALUES('"+tNama.getText()+"','"+tAlamat.getText()+"',"
                    + "'"+tTelepon.getText()+"')";
                    int status = classkoneksi.execute(SQL);
                    if(status == 1) {
                        JOptionPane.showMessageDialog(this, "data berhasil ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
                    } else {
                      JOptionPane.showMessageDialog(this, "data gagal ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE ); 
                    }
        }
       
    }
   
   
    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if(btnSimpan.getText().equals("Ubah")){
            updateData();
        }else{
            simpan();
        }
       
    }                                        

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

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

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                 
        // TODO add your handling code here:
        if(this.isUpdate()==true){
            pushData();
            btnSimpan.setText("Ubah");
        }else{
            btnSimpan.setText("Simpan");
        }
    }                                

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

    // Variables declaration - do not modify                    
    private javax.swing.JButton btnSimpan;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tAlamat;
    private javax.swing.JTextField tNama;
    private javax.swing.JTextField tTelepon;
    // End of variables declaration                  

    /**
     * @return the namaDistributor
     */
    public String getNamaDistributor() {
        return namaDistributor;
    }

    /**
     * @param namaDistributor the namaDistributor to set
     */
    public void setNamaDistributor(String namaDistributor) {
        this.namaDistributor = namaDistributor;
    }

    /**
     * @return the alamatDistributor
     */
    public String getAlamatDistributor() {
        return alamatDistributor;
    }

    /**
     * @param alamatDistributor the alamatDistributor to set
     */
    public void setAlamatDistributor(String alamatDistributor) {
        this.alamatDistributor = alamatDistributor;
    }

    /**
     * @return the teleponDistributor
     */
    public String getTeleponDistributor() {
        return teleponDistributor;
    }

    /**
     * @param teleponDistributor the teleponDistributor to set
     */
    public void setTeleponDistributor(String teleponDistributor) {
        this.teleponDistributor = teleponDistributor;
    }

    /**
     * @return the update
     */
    public boolean isUpdate() {
        return update;
    }

    /**
     * @param update the update to set
     */
    public void setUpdate(boolean update) {
        this.update = update;
    }
}

Comments

Popular posts from this blog

contoh proposal asistem aplikasi jasa laundry

Naskah Drama Bahasa Sunda

penjualan