Abdurrahman Aqil

My notes~

Saturday, November 16, 2019

Program Mini Kalkulator

Mini Kalkulator

Editor : Netbeans 8.2

Tampilan Program


Palette
Text
Variable Name
jLabel1
Mini Kalkulator

jlabel2
Bilangan 1

jLabel3
Bilangan 2

jTextField1

bil1
jTextField2

bil2
jTextField3

hasil
jButton1
+
Tambah
jButton2
*
Kali
jButton3
-
Kurang
jButton4
/
Bagi
jButton5
C
Clear
jButton6
Exit
Exit

Source Code :
Untuk menambahkan perintah pada tiap tombol, cukup dengan double-click pada tombol yang ingin kita beri perintah.

//Tombol Tambah
   private void TambahActionPerformed(java.awt.event.ActionEvent evt) {                                       
    //Deklarasi variabel & text field    
    int a = Integer.parseInt(bil1.getText());
    int b = Integer.parseInt(bil2.getText());    
    //rumus / proses
    int c = a + b;    
    //menampilkan hasil proses
    hasil.setText(String.valueOf(c));
    }  
//Tombol Kali
   private void KurangActionPerformed(java.awt.event.ActionEvent evt) {                                       
    int a = Integer.parseInt(bil1.getText());
    int b = Integer.parseInt(bil2.getText());
    int c = a - b;
    hasil.setText(String.valueOf(c));// TODO add your handling code here:
    }  
//Tombol Kurang
    private void KurangActionPerformed(java.awt.event.ActionEvent evt) {                                       
        int a = Integer.parseInt(bil1.getText());
    int b = Integer.parseInt(bil2.getText());
    int c = a - b;
    hasil.setText(String.valueOf(c));// TODO add your handling code here:
    }  
//Tombol Bagi
   private void BagiActionPerformed(java.awt.event.ActionEvent evt) {                                     
   int a = Integer.parseInt(bil1.getText());
    int b = Integer.parseInt(bil2.getText());
    int c = a / b;
    hasil.setText(String.valueOf(c));        // TODO add your handling code here:
    } 
//Tombol Clear
    private void ClearActionPerformed(java.awt.event.ActionEvent evt) {                                      
bil1.setText("");
bil2.setText("");
hasil.setText("");
    }
//Tombol Exit
 private void ExitActionPerformed(java.awt.event.ActionEvent evt) {                                     
System.exit(0);       
    } 

No comments:

Post a Comment