Social Items

SPACE IKLAN ( ADS ) CLICK HERE
kalkulator-java-netbeans-sederhana-kuliah-teknik-informatika

Kalkulator Java Netbeans Sederhana Kuliah Teknik Informatikakalkulator adalah alat untuk menghitung dari perhitungan sederhana seperti penjumlahan, pengurangan, perkalian dan pembagian sampai kepada kalkulator sains yang dapat menghitung rumus matematika tertentu.
Pada perkembangannya sekarang ini, kalkulator sering dimasukkan sebagai fungsi tambahan daripada komputer, handphone, bahkan sampai jam tangan.





Langkah Pertama

  • Open Netbeanse and Click File
  • Lalu create new project
  • Categories Java | Project  Java Application
  • Click next
  • Isikan Project Name "KalkulatorSederhana"
  • Centang pada create main class ( opsional )
  • Finish

Langkah Kedua

  • Click kanan Java Project KalkulatorSederhana
  • New
  • Pilih jFrom Interface...
  • Isikan Class name "Kalkulator" dan Pakckage "Kalkulators"

Langkah Ketiga

kalkulator-java-netbeans-sederhana-kuliah-teknik-informatika
Gambar Design Kalkulator Java 1.1


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

/**
 *
 * @author Dani
 */
public class CalculatorYogi extends javax.swing.JFrame {

    /**
     * Creates new form CalculatorYogi
     */
    double firstnum;
    double secondnum;
    double result;
    String operations;
    String Enternumber;
    
    public CalculatorYogi() {
        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")
    //                           
    private void initComponents() {

        jDisplay = new javax.swing.JTextField();
        jBtn1 = new javax.swing.JButton();
        jBtn2 = new javax.swing.JButton();
        jBtn3 = new javax.swing.JButton();
        jBtn4 = new javax.swing.JButton();
        jBtn5 = new javax.swing.JButton();
        jBtn6 = new javax.swing.JButton();
        jBtn7 = new javax.swing.JButton();
        jBtn8 = new javax.swing.JButton();
        jBtn9 = new javax.swing.JButton();
        jBtn10 = new javax.swing.JButton();
        jBtn11 = new javax.swing.JButton();
        jBtn12 = new javax.swing.JButton();
        jBtn13 = new javax.swing.JButton();
        jBtn14 = new javax.swing.JButton();
        jBtn15 = new javax.swing.JButton();
        jBtn16 = new javax.swing.JButton();
        jBtn17 = new javax.swing.JButton();
        jBtn18 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jDisplay.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jDisplay.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jDisplay.setToolTipText("");
        jDisplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDisplayActionPerformed(evt);
            }
        });

        jBtn1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn1.setText("1");
        jBtn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn1ActionPerformed(evt);
            }
        });

        jBtn2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn2.setText("2");
        jBtn2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn2ActionPerformed(evt);
            }
        });

        jBtn3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn3.setText("3");
        jBtn3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn3ActionPerformed(evt);
            }
        });

        jBtn4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn4.setText("4");
        jBtn4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn4ActionPerformed(evt);
            }
        });

        jBtn5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn5.setText("5");
        jBtn5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn5ActionPerformed(evt);
            }
        });

        jBtn6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn6.setText("6");
        jBtn6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn6ActionPerformed(evt);
            }
        });

        jBtn7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn7.setText("7");
        jBtn7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn7ActionPerformed(evt);
            }
        });

        jBtn8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn8.setText("8");
        jBtn8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn8ActionPerformed(evt);
            }
        });

        jBtn9.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn9.setText("9");
        jBtn9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn9ActionPerformed(evt);
            }
        });

        jBtn10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn10.setText("0");
        jBtn10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn10ActionPerformed(evt);
            }
        });

        jBtn11.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn11.setText("+");
        jBtn11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn11ActionPerformed(evt);
            }
        });

        jBtn12.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn12.setText("-");

        jBtn13.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn13.setText("/");

        jBtn14.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn14.setText("*");

        jBtn15.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn15.setText("+/-");

        jBtn16.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn16.setText(".");

        jBtn17.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn17.setText("C");
        jBtn17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn17ActionPerformed(evt);
            }
        });

        jBtn18.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn18.setText("=");
        jBtn18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn18ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jDisplay)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn4, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtn5, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn6, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn7, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn8, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtn9, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn10, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn11, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn12, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jBtn17, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jBtn13, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jBtn14, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jBtn15, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jBtn16, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jBtn18, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 9, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn5, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn6, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn7, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn8, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn9, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn10, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn11, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn12, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn13, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn14, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn15, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn16, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn17, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn18, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }//                         

    
    private void jDisplayActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
    }                                        

    private void jBtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn1.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn2ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn2.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn3ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn3.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn4ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn4.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn5ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn5.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn6ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn6.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn7ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn7.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn8ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn8.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn9ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn9.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn10ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        Enternumber = jDisplay.getText() + jBtn10.getText();
        jDisplay.setText(Enternumber);
        
    }                                      

    private void jBtn11ActionPerformed(java.awt.event.ActionEvent evt) {                                       
       
        firstnum = Double.parseDouble(jDisplay.getText());
        jDisplay.setText("+");
        operations="+"; 
        
    }                                      

    private void jBtn18ActionPerformed(java.awt.event.ActionEvent evt) {                                       
         String answer;
         
         secondnum = Double.parseDouble(jDisplay.getText());
         if(operations == "+")
         {
             result = firstnum + secondnum;
             answer = String.format("%.0f",result);
             
             jDisplay.setText(answer);
         }
    }                                      

    private void jBtn17ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        jDisplay.setText("");
    }                                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //
        /* 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(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CalculatorYogi().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jBtn1;
    private javax.swing.JButton jBtn10;
    private javax.swing.JButton jBtn11;
    private javax.swing.JButton jBtn12;
    private javax.swing.JButton jBtn13;
    private javax.swing.JButton jBtn14;
    private javax.swing.JButton jBtn15;
    private javax.swing.JButton jBtn16;
    private javax.swing.JButton jBtn17;
    private javax.swing.JButton jBtn18;
    private javax.swing.JButton jBtn2;
    private javax.swing.JButton jBtn3;
    private javax.swing.JButton jBtn4;
    private javax.swing.JButton jBtn5;
    private javax.swing.JButton jBtn6;
    private javax.swing.JButton jBtn7;
    private javax.swing.JButton jBtn8;
    private javax.swing.JButton jBtn9;
    private javax.swing.JTextField jDisplay;
    // End of variables declaration                   
}


  • TIPS
  • ketikan "psvm" pada java netbeans IDE, lalu pencet tombol tab dan lihat apa yang terjadi
Click Tombol FULLCODE Untuk Melihat Source Code Full nya.

  • Masukan full code Kalkulator Java di atas atau Rewrite source code nya dan shift + f6 untuk run program atau click kanan pada file KalkulatorSederhana.java, lalu pilih run file.
  • ATAU
  • Ikut Manual tutorial Berikut , tetapi kalian harus mendesign tampilanya , sebetulnya code nya singkat saja , namun di atas ( full source code ) itu adalah fold code dari componen design nya dan tidak perlu mengkoding seluruh code , simak langkah mudah nya.

Langkah - Langkah Mudah Kalkulator Java

  • Buat design seperti Gambar Design Kalkulator Java 1.1
  • Ket Componen Design Pallete : JSWING = textfield (1) , Button (buat 1 saja , lalu click kanan pada button nya dan pilih duplikat )

  • NB : Click source ( disamping design ) atau double click ke salah satu componen atau bukan componen ( bagian design ) maka langsung terpindah ke source program

Langkah Selanjutnya

  • Click TextField , muncul [jTextField] Properti yang ada di pojok kanan 
  • Pilih Tab Code
  • Berikan Variable names jDisplay (opsional terserah anda)
  • Pilih Propertis
  • Kosongkan saja text pada jTextField
  • Buat ( drag ) Button yang ada di Pallete window ( Swing Controls )
  • Berikan variable names dan isi properties text menjadi angka "1"
  • Duplicate tombol button tersebut , pindahkan ke samping tombol 1.
  • Drag select kedua tombol , dan duplicate lagi , hingga seperti gambar design kalkulator 1.1.

Langkah Coding nya

  • Buat Deklrasai code nya di dalam public class KalkulatorSederhana extends javax.swing.JFrame {
  • Seperti berikut

public class CalculatorYogi extends javax.swing.JFrame {

    /**
     * Creates new form CalculatorYogi
     */
    double firstnum;
    double secondnum;
    double result;
    String operations;
    String Enternumber;
    
    public CalculatorYogi() {
        initComponents();
    }
  • Pilih tab design dan Double Click pada Button 1
  • Maka kalian akan masuk ke bagian code ini

 private void jBtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        //code here @aw.yogi
    }  
  • Ketik listing code berikut

Enternumber = jDisplay.getText() + jBtn1.getText();
jDisplay.setText(Enternumber);
  • Maka akan terlihat seperti ini

 private void jBtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn1.getText();
        jDisplay.setText(Enternumber);
    }
  • Lakukan Langkah yang sama tersebut terhadap tombol button 2. tetapi ubah sytn jBtn1.getText(); menjadi jBtn2.getText(); sesuai variable names yang kalian kasih pada tombol tersebut.

Option Tambah Kalkulator  Java

  • Double Click pada tombol tambah (+)
  • Masukan code ini

 firstnum = Double.parseDouble(jDisplay.getText());
        jDisplay.setText("+"); //opsional like you "" only or etc
        operations="+"; 
  • jDisplay adalah variable names textfield.
  • Silahkan Lakukan hal yang sama pada tombol pengurangan , bagi, kali, dan sisa bagi ( tetapi mengubah operations menjadi - atau / atau * untuk kali.

Option Sama Dengan atau Hasil

  • Lakukan hal yang sama , double click tombol sama dengan =
  • Write code ini

String answer;
         
         secondnum = Double.parseDouble(jDisplay.getText());
         if(operations == "+")
         {
             result = firstnum + secondnum;
             answer = String.format("%.0f",result);
             
             jDisplay.setText(answer);
         } //silahkan tambahkan list code if lagi , untuk pengurangan, tetapi jangan lupa untuk mengubah operation nya

Tombol Delete atau Hapus TextField Java


 jDisplay.setText("");

  • untuk tombol titik alias koma , sama seperti code di atas tinggal masukan titik pada "."
  • jalankan program ( shit + f6 ) atau click kanan pada main class name KalkulatorSederhana dan pilih run file
kalkulator-java-netbeans-sederhana-kuliah-teknik-informatika
Output Kalkulator Sederhana Java Netbeans

Video Tutorial Kalkulator Java Netbeans Sederhana Kuliah Teknik Informatika

[tomorrow] [besok] update
==========================
Thanks for
==========================
Java
Netbeans
==========================

Thanks for read | Terima Kasih Sudah Membaca
Semoga Bermanfaat dan Code nya bisa running , dan yang error bisa komen pada kolom komentar di bawah. . .

Kalkulator Java Netbeans Sederhana Kuliah Teknik Informatika

kalkulator-java-netbeans-sederhana-kuliah-teknik-informatika

Kalkulator Java Netbeans Sederhana Kuliah Teknik Informatikakalkulator adalah alat untuk menghitung dari perhitungan sederhana seperti penjumlahan, pengurangan, perkalian dan pembagian sampai kepada kalkulator sains yang dapat menghitung rumus matematika tertentu.
Pada perkembangannya sekarang ini, kalkulator sering dimasukkan sebagai fungsi tambahan daripada komputer, handphone, bahkan sampai jam tangan.





Langkah Pertama

  • Open Netbeanse and Click File
  • Lalu create new project
  • Categories Java | Project  Java Application
  • Click next
  • Isikan Project Name "KalkulatorSederhana"
  • Centang pada create main class ( opsional )
  • Finish

Langkah Kedua

  • Click kanan Java Project KalkulatorSederhana
  • New
  • Pilih jFrom Interface...
  • Isikan Class name "Kalkulator" dan Pakckage "Kalkulators"

Langkah Ketiga

kalkulator-java-netbeans-sederhana-kuliah-teknik-informatika
Gambar Design Kalkulator Java 1.1


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

/**
 *
 * @author Dani
 */
public class CalculatorYogi extends javax.swing.JFrame {

    /**
     * Creates new form CalculatorYogi
     */
    double firstnum;
    double secondnum;
    double result;
    String operations;
    String Enternumber;
    
    public CalculatorYogi() {
        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")
    //                           
    private void initComponents() {

        jDisplay = new javax.swing.JTextField();
        jBtn1 = new javax.swing.JButton();
        jBtn2 = new javax.swing.JButton();
        jBtn3 = new javax.swing.JButton();
        jBtn4 = new javax.swing.JButton();
        jBtn5 = new javax.swing.JButton();
        jBtn6 = new javax.swing.JButton();
        jBtn7 = new javax.swing.JButton();
        jBtn8 = new javax.swing.JButton();
        jBtn9 = new javax.swing.JButton();
        jBtn10 = new javax.swing.JButton();
        jBtn11 = new javax.swing.JButton();
        jBtn12 = new javax.swing.JButton();
        jBtn13 = new javax.swing.JButton();
        jBtn14 = new javax.swing.JButton();
        jBtn15 = new javax.swing.JButton();
        jBtn16 = new javax.swing.JButton();
        jBtn17 = new javax.swing.JButton();
        jBtn18 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jDisplay.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jDisplay.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jDisplay.setToolTipText("");
        jDisplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDisplayActionPerformed(evt);
            }
        });

        jBtn1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn1.setText("1");
        jBtn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn1ActionPerformed(evt);
            }
        });

        jBtn2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn2.setText("2");
        jBtn2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn2ActionPerformed(evt);
            }
        });

        jBtn3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn3.setText("3");
        jBtn3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn3ActionPerformed(evt);
            }
        });

        jBtn4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn4.setText("4");
        jBtn4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn4ActionPerformed(evt);
            }
        });

        jBtn5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn5.setText("5");
        jBtn5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn5ActionPerformed(evt);
            }
        });

        jBtn6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn6.setText("6");
        jBtn6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn6ActionPerformed(evt);
            }
        });

        jBtn7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn7.setText("7");
        jBtn7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn7ActionPerformed(evt);
            }
        });

        jBtn8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn8.setText("8");
        jBtn8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn8ActionPerformed(evt);
            }
        });

        jBtn9.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn9.setText("9");
        jBtn9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn9ActionPerformed(evt);
            }
        });

        jBtn10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn10.setText("0");
        jBtn10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn10ActionPerformed(evt);
            }
        });

        jBtn11.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn11.setText("+");
        jBtn11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn11ActionPerformed(evt);
            }
        });

        jBtn12.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn12.setText("-");

        jBtn13.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn13.setText("/");

        jBtn14.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn14.setText("*");

        jBtn15.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn15.setText("+/-");

        jBtn16.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn16.setText(".");

        jBtn17.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn17.setText("C");
        jBtn17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn17ActionPerformed(evt);
            }
        });

        jBtn18.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jBtn18.setText("=");
        jBtn18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn18ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jDisplay)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn4, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtn5, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn6, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn7, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn8, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtn9, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn10, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn11, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBtn12, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jBtn17, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jBtn13, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jBtn14, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jBtn15, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jBtn16, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jBtn18, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 9, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn5, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn6, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn7, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn8, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn9, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn10, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn11, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn12, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn13, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn14, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn15, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn16, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn17, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtn18, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }//                         

    
    private void jDisplayActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
    }                                        

    private void jBtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn1.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn2ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn2.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn3ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn3.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn4ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn4.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn5ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn5.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn6ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn6.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn7ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn7.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn8ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn8.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn9ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn9.getText();
        jDisplay.setText(Enternumber);
    }                                     

    private void jBtn10ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        Enternumber = jDisplay.getText() + jBtn10.getText();
        jDisplay.setText(Enternumber);
        
    }                                      

    private void jBtn11ActionPerformed(java.awt.event.ActionEvent evt) {                                       
       
        firstnum = Double.parseDouble(jDisplay.getText());
        jDisplay.setText("+");
        operations="+"; 
        
    }                                      

    private void jBtn18ActionPerformed(java.awt.event.ActionEvent evt) {                                       
         String answer;
         
         secondnum = Double.parseDouble(jDisplay.getText());
         if(operations == "+")
         {
             result = firstnum + secondnum;
             answer = String.format("%.0f",result);
             
             jDisplay.setText(answer);
         }
    }                                      

    private void jBtn17ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        jDisplay.setText("");
    }                                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //
        /* 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(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CalculatorYogi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CalculatorYogi().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jBtn1;
    private javax.swing.JButton jBtn10;
    private javax.swing.JButton jBtn11;
    private javax.swing.JButton jBtn12;
    private javax.swing.JButton jBtn13;
    private javax.swing.JButton jBtn14;
    private javax.swing.JButton jBtn15;
    private javax.swing.JButton jBtn16;
    private javax.swing.JButton jBtn17;
    private javax.swing.JButton jBtn18;
    private javax.swing.JButton jBtn2;
    private javax.swing.JButton jBtn3;
    private javax.swing.JButton jBtn4;
    private javax.swing.JButton jBtn5;
    private javax.swing.JButton jBtn6;
    private javax.swing.JButton jBtn7;
    private javax.swing.JButton jBtn8;
    private javax.swing.JButton jBtn9;
    private javax.swing.JTextField jDisplay;
    // End of variables declaration                   
}


  • TIPS
  • ketikan "psvm" pada java netbeans IDE, lalu pencet tombol tab dan lihat apa yang terjadi
Click Tombol FULLCODE Untuk Melihat Source Code Full nya.

  • Masukan full code Kalkulator Java di atas atau Rewrite source code nya dan shift + f6 untuk run program atau click kanan pada file KalkulatorSederhana.java, lalu pilih run file.
  • ATAU
  • Ikut Manual tutorial Berikut , tetapi kalian harus mendesign tampilanya , sebetulnya code nya singkat saja , namun di atas ( full source code ) itu adalah fold code dari componen design nya dan tidak perlu mengkoding seluruh code , simak langkah mudah nya.

Langkah - Langkah Mudah Kalkulator Java

  • Buat design seperti Gambar Design Kalkulator Java 1.1
  • Ket Componen Design Pallete : JSWING = textfield (1) , Button (buat 1 saja , lalu click kanan pada button nya dan pilih duplikat )

  • NB : Click source ( disamping design ) atau double click ke salah satu componen atau bukan componen ( bagian design ) maka langsung terpindah ke source program

Langkah Selanjutnya

  • Click TextField , muncul [jTextField] Properti yang ada di pojok kanan 
  • Pilih Tab Code
  • Berikan Variable names jDisplay (opsional terserah anda)
  • Pilih Propertis
  • Kosongkan saja text pada jTextField
  • Buat ( drag ) Button yang ada di Pallete window ( Swing Controls )
  • Berikan variable names dan isi properties text menjadi angka "1"
  • Duplicate tombol button tersebut , pindahkan ke samping tombol 1.
  • Drag select kedua tombol , dan duplicate lagi , hingga seperti gambar design kalkulator 1.1.

Langkah Coding nya

  • Buat Deklrasai code nya di dalam public class KalkulatorSederhana extends javax.swing.JFrame {
  • Seperti berikut

public class CalculatorYogi extends javax.swing.JFrame {

    /**
     * Creates new form CalculatorYogi
     */
    double firstnum;
    double secondnum;
    double result;
    String operations;
    String Enternumber;
    
    public CalculatorYogi() {
        initComponents();
    }
  • Pilih tab design dan Double Click pada Button 1
  • Maka kalian akan masuk ke bagian code ini

 private void jBtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        //code here @aw.yogi
    }  
  • Ketik listing code berikut

Enternumber = jDisplay.getText() + jBtn1.getText();
jDisplay.setText(Enternumber);
  • Maka akan terlihat seperti ini

 private void jBtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Enternumber = jDisplay.getText() + jBtn1.getText();
        jDisplay.setText(Enternumber);
    }
  • Lakukan Langkah yang sama tersebut terhadap tombol button 2. tetapi ubah sytn jBtn1.getText(); menjadi jBtn2.getText(); sesuai variable names yang kalian kasih pada tombol tersebut.

Option Tambah Kalkulator  Java

  • Double Click pada tombol tambah (+)
  • Masukan code ini

 firstnum = Double.parseDouble(jDisplay.getText());
        jDisplay.setText("+"); //opsional like you "" only or etc
        operations="+"; 
  • jDisplay adalah variable names textfield.
  • Silahkan Lakukan hal yang sama pada tombol pengurangan , bagi, kali, dan sisa bagi ( tetapi mengubah operations menjadi - atau / atau * untuk kali.

Option Sama Dengan atau Hasil

  • Lakukan hal yang sama , double click tombol sama dengan =
  • Write code ini

String answer;
         
         secondnum = Double.parseDouble(jDisplay.getText());
         if(operations == "+")
         {
             result = firstnum + secondnum;
             answer = String.format("%.0f",result);
             
             jDisplay.setText(answer);
         } //silahkan tambahkan list code if lagi , untuk pengurangan, tetapi jangan lupa untuk mengubah operation nya

Tombol Delete atau Hapus TextField Java


 jDisplay.setText("");

  • untuk tombol titik alias koma , sama seperti code di atas tinggal masukan titik pada "."
  • jalankan program ( shit + f6 ) atau click kanan pada main class name KalkulatorSederhana dan pilih run file
kalkulator-java-netbeans-sederhana-kuliah-teknik-informatika
Output Kalkulator Sederhana Java Netbeans

Video Tutorial Kalkulator Java Netbeans Sederhana Kuliah Teknik Informatika

[tomorrow] [besok] update
==========================
Thanks for
==========================
Java
Netbeans
==========================

Thanks for read | Terima Kasih Sudah Membaca
Semoga Bermanfaat dan Code nya bisa running , dan yang error bisa komen pada kolom komentar di bawah. . .
Load Comments

Subscribe Our Newsletter