UTS Membuat Aplikasi Kalkulator Gaji dengan Java NetBeans

NAMA

NIM

KELAS

: Ferry Ananda Febian

: 19.12.023

: TIB-1A

Dosen

MK

Deadline

: Nasruddin Bin Idris, S.Kom.,M.Kom

: Algoritma dan Teknik Pemrograman

: Jum’at, 1 Mei 2020


Screen hasil output :

Source code

FormPerhitungan.java

/*

 * 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 FERRY ANANDA FEBIAN

 */

public class FormPerhitungan extends javax.swing.JFrame {


    /**

     * Creates new form FormPerhitungan

     */

    public FormPerhitungan() {

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


        jLabel1 = new javax.swing.JLabel();

        jLabel2 = new javax.swing.JLabel();

        jLabel3 = new javax.swing.JLabel();

        jLabel4 = new javax.swing.JLabel();

        jLabel5 = new javax.swing.JLabel();

        jLabel6 = new javax.swing.JLabel();

        txtlamabekerja = new javax.swing.JTextField();

        txtuangmakan = new javax.swing.JTextField();

        txtgaji = new javax.swing.JTextField();

        txtnama = new javax.swing.JTextField();

        txtbiayatranspot = new javax.swing.JTextField();

        jLabel7 = new javax.swing.JLabel();

        jLabel8 = new javax.swing.JLabel();

        jLabel9 = new javax.swing.JLabel();

        btnhasil = new javax.swing.JButton();

        setarea = new javax.swing.JLabel();

        setarea1 = new javax.swing.JLabel();

        settranspot = new javax.swing.JLabel();

        setuangmakan = new javax.swing.JLabel();

        setgajiditerima = new javax.swing.JLabel();

        transpotdanmakan = new javax.swing.JLabel();

        reset = new javax.swing.JButton();

        jLabel10 = new javax.swing.JLabel();

        jLabel11 = new javax.swing.JLabel();

        jLabel12 = new javax.swing.JLabel();

        jLabel13 = new javax.swing.JLabel();

        jLabel14 = new javax.swing.JLabel();

        jLabel15 = new javax.swing.JLabel();


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


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

        jLabel1.setText("KALKULATOR GAJI PEGAWAI");


        jLabel2.setText("NAMA");


        jLabel3.setText("GAJI SEHARI (Rp)");


        jLabel4.setText("LAMA BEKERJA");


        jLabel5.setText("BIAYA TRANSPOT");


        jLabel6.setText("UANG MAKAN");


        txtgaji.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

        txtgaji.setDoubleBuffered(true);

        txtgaji.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                txtgajiActionPerformed(evt);

            }

        });

        txtgaji.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyTyped(java.awt.event.KeyEvent evt) {

                txtgajiKeyTyped(evt);

            }

        });


        txtnama.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                txtnamaActionPerformed(evt);

            }

        });


        jLabel7.setText("HARI");


        jLabel8.setText("/ HARI");


        jLabel9.setText("/ HARI");


        btnhasil.setText("HASIL");

        btnhasil.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                btnhasilActionPerformed(evt);

            }

        });


        reset.setText("RESET");

        reset.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                resetActionPerformed(evt);

            }

        });


        jLabel10.setText("Nama Karyawan :");


        jLabel11.setText("Gaji :");


        jLabel12.setText("Biaya Transpot :");


        jLabel13.setText("Uang Makan :");


        jLabel14.setText("Transpot dan Makan :");


        jLabel15.setText("Gaji Diterima :");


        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(layout.createSequentialGroup()

                        .addGap(170, 170, 170)

                        .addComponent(jLabel1))

                    .addGroup(layout.createSequentialGroup()

                        .addGap(52, 52, 52)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)

                                .addComponent(btnhasil, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                                .addComponent(reset, javax.swing.GroupLayout.Alignment.LEADING))

                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                                .addComponent(jLabel3)

                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)

                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))

                            .addComponent(jLabel5)

                            .addComponent(jLabel6))

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(layout.createSequentialGroup()

                                .addGap(18, 18, 18)

                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                                    .addComponent(txtgaji, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)

                                    .addGroup(layout.createSequentialGroup()

                                        .addComponent(txtlamabekerja, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)

                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addComponent(jLabel7))

                                    .addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)

                                    .addGroup(layout.createSequentialGroup()

                                        .addComponent(txtbiayatranspot, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)

                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addComponent(jLabel8))

                                    .addGroup(layout.createSequentialGroup()

                                        .addComponent(txtuangmakan, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)

                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addComponent(jLabel9))))

                            .addGroup(layout.createSequentialGroup()

                                .addGap(58, 58, 58)

                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                                    .addComponent(jLabel10)

                                    .addComponent(jLabel11)

                                    .addComponent(jLabel12)

                                    .addComponent(jLabel13)

                                    .addComponent(jLabel14)

                                    .addComponent(jLabel15))

                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                                    .addComponent(setarea1)

                                    .addComponent(settranspot)

                                    .addComponent(setuangmakan)

                                    .addComponent(setgajiditerima)

                                    .addComponent(transpotdanmakan)

                                    .addComponent(setarea))))))

                .addContainerGap(187, Short.MAX_VALUE))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(jLabel1)

                .addGap(18, 18, 18)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jLabel2)

                    .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(jLabel3)

                    .addComponent(txtgaji, 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(jLabel4)

                    .addComponent(txtlamabekerja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jLabel7))

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(layout.createSequentialGroup()

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                            .addComponent(jLabel8)

                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                                .addComponent(txtbiayatranspot, 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(txtuangmakan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(jLabel9)

                            .addComponent(jLabel6))

                        .addGap(18, 18, 18)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(setarea)

                            .addComponent(jLabel10))

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(setarea1)

                            .addComponent(jLabel11))

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(settranspot)

                            .addComponent(jLabel12))

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(setuangmakan)

                            .addComponent(jLabel13))

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(transpotdanmakan)

                            .addComponent(jLabel14))

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(setgajiditerima)

                            .addComponent(jLabel15)))

                    .addGroup(layout.createSequentialGroup()

                        .addGap(68, 68, 68)

                        .addComponent(btnhasil)

                        .addGap(12, 12, 12)

                        .addComponent(reset)))

                .addContainerGap(151, Short.MAX_VALUE))

        );


        pack();

    }// </editor-fold>                        


    private void txtnamaActionPerformed(java.awt.event.ActionEvent evt) {                                        

        // TODO add your handling code here:

    }                                       


    private void txtgajiActionPerformed(java.awt.event.ActionEvent evt) {                                        

        // TODO add your handling code here:

    }                                       


    private void btnhasilActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // buat variabel:

        String nama=txtnama.getText();

        int gaji=Integer.valueOf(txtgaji.getText());

        int lamabekerja=Integer.valueOf(txtlamabekerja.getText());

        int uangtranspot=Integer.valueOf(txtbiayatranspot.getText());

        int uangmakan=Integer.valueOf(txtuangmakan.getText());

        

        int hasil=gaji*lamabekerja;

        int gajiditerima=((gaji*lamabekerja)-((uangtranspot+uangmakan)*lamabekerja));

        int biayamakan=(uangmakan*lamabekerja);

        int biayatranspot=(uangtranspot*lamabekerja);

        int makantranspot=biayamakan+biayatranspot;

                

                

         setarea.setText(nama); 

         setarea1.setText(String.valueOf(hasil));

         settranspot.setText(String.valueOf(biayatranspot));

         setuangmakan.setText(String.valueOf(biayamakan));

         transpotdanmakan.setText(String.valueOf(biayamakan)+"+"+String.valueOf(biayatranspot)+"="+String.valueOf(makantranspot));

         setgajiditerima.setText("Rp."+String.valueOf(gajiditerima));

         

         

    }                                        


    private void txtgajiKeyTyped(java.awt.event.KeyEvent evt) {                                 

        // TODO add your handling code here:

        char enter=evt.getKeyChar();

        if(!(Character.isDigit(enter)))

        {

            evt.consume();

        }

    }                                


    private void resetActionPerformed(java.awt.event.ActionEvent evt) {                                      

        // TODO add your handling code here:

        txtnama.setText(""); // del text input

        txtbiayatranspot.setText(""); // del text input

        txtgaji.setText(""); // del text input

        txtlamabekerja.setText(""); // del text input

        txtuangmakan.setText(""); // del text input   

        

        

        setarea.setText(""); // del text input   

        setarea1.setText(""); // del text input   

        settranspot.setText(""); // del text input   

        setuangmakan.setText(""); // del text input   

        transpotdanmakan.setText(""); // del text input   

        setgajiditerima.setText(""); // del text input   

        

    }                                     


    /**

     * @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(FormPerhitungan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(FormPerhitungan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(FormPerhitungan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(FormPerhitungan.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 FormPerhitungan().setVisible(true);

            }

        });

    }


    // Variables declaration - do not modify                     

    private javax.swing.JButton btnhasil;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel10;

    private javax.swing.JLabel jLabel11;

    private javax.swing.JLabel jLabel12;

    private javax.swing.JLabel jLabel13;

    private javax.swing.JLabel jLabel14;

    private javax.swing.JLabel jLabel15;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JLabel jLabel4;

    private javax.swing.JLabel jLabel5;

    private javax.swing.JLabel jLabel6;

    private javax.swing.JLabel jLabel7;

    private javax.swing.JLabel jLabel8;

    private javax.swing.JLabel jLabel9;

    private javax.swing.JButton reset;

    private javax.swing.JLabel setarea;

    private javax.swing.JLabel setarea1;

    private javax.swing.JLabel setgajiditerima;

    private javax.swing.JLabel settranspot;

    private javax.swing.JLabel setuangmakan;

    private javax.swing.JLabel transpotdanmakan;

    private javax.swing.JTextField txtbiayatranspot;

    private javax.swing.JTextField txtgaji;

    private javax.swing.JTextField txtlamabekerja;

    private javax.swing.JTextField txtnama;

    private javax.swing.JTextField txtuangmakan;

    // End of variables declaration                   

}


Posting Komentar

0 Komentar