Membuat Kalkulator dengan Netbeans (java) partII

on

Kemaren pada postingan sebelumnya saya sudah pernah memberikan sedikit tutorial untuk membuat kalkulator sederhana bisa dilihat disini Membuat Kalkulator Sederhana dengan Netbeans tapi dengan dua inputan.. kali ini saya akan mencoba mengulas cara membuat Kalkulator yang lebih komplit lagi. langsung aja berikut Outputnya:


komponentnya:
1. JTextFiled: 1 dengan nama variabel: txtLayar
2. JButton: 18 dengan nama variabel btnsatu,btndua,btntiga,btnempat,btnlima,btnenam,btntujuh,
btndelapan,btnsembilan,btnnol,btnkali,btnbagi,btntambah,btnkurang,btnclear,btnsamadengan,btnpersen,btnexit
3. JLabel: 2: By Hand Excel & KALKULATOR

dan Berikut Scriptnya:
public class kalkulator extends javax.swing.JFrame {
String angka;
double total, bilanganSatu, bilanganDua;    int pilihan;

private void btnnolActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”0″;
txtLayar.setText(angka); //untuk button 0

}

private void btnclearActionPerformed(java.awt.event.ActionEvent evt) {
txtLayar.setText(“”);
bilanganSatu = 0;
bilanganDua  = 0; //untuk button C
total = 0;
angka =””;

}

private void btnsamadenganActionPerformed(java.awt.event.ActionEvent evt) {
switch(pilihan){
case 1:
bilanganDua = Double.parseDouble(angka); //untuk button =
total = bilanganSatu / bilanganDua;
angka = Double.toString(total);
txtLayar.setText(angka);
break;
case 2:
bilanganDua = Double.parseDouble(angka);
total = bilanganSatu + bilanganDua;
angka = Double.toString(total);
txtLayar.setText(angka);
break;
case 3:
bilanganDua = Double.parseDouble(angka);
total = bilanganSatu – bilanganDua;
angka = Double.toString(total);
txtLayar.setText(angka);
break;
case 4:
bilanganDua = Double.parseDouble(angka);
total = bilanganSatu * bilanganDua;
angka = Double.toString(total);
txtLayar.setText(angka);
break;
case 5:
bilanganDua = Double.parseDouble(angka);
total = 0.01*bilanganDua;
angka = Double.toString(total);
txtLayar.setText(angka);

break;
default:
break;

}

}

private void btnkaliActionPerformed(java.awt.event.ActionEvent evt) {
bilanganSatu = Double.parseDouble(angka);
txtLayar.setText(“*”); //untuk button x
angka =””;
pilihan =4;

}

private void btnbagiActionPerformed(java.awt.event.ActionEvent evt) {
bilanganSatu = Double.parseDouble(angka);
txtLayar.setText(“/”);
angka =””;
pilihan =1;

}

private void btntambahActionPerformed(java.awt.event.ActionEvent evt) {
bilanganSatu = Double.parseDouble(angka);
txtLayar.setText(“+”); //untuk button +
angka =””;
pilihan =2;

}

private void btnkurangActionPerformed(java.awt.event.ActionEvent evt) {
bilanganSatu = Double.parseDouble(angka);
txtLayar.setText(“-“); //untuk button –
angka =””;
pilihan =3;

}

private void btnsatuActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”1″; //untuk button 1
txtLayar.setText(angka);

}

private void btnduaActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”2″; //untuk button 2
txtLayar.setText(angka);

}

private void btntigaActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”3″; //untuk button 3
txtLayar.setText(angka);

}

private void btnempatActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”4″; //untuk button 4
txtLayar.setText(angka);

}

private void btnlimaActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”5″; //untuk button 5
txtLayar.setText(angka);

}

private void btnenamActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”6″; //untuk button 6
txtLayar.setText(angka);

}

private void btntujuhActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”7″; //untuk button 7
txtLayar.setText(angka);

}

private void btndelapanActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”8″; //untuk button 8
txtLayar.setText(angka);

}

private void btnsembilanActionPerformed(java.awt.event.ActionEvent evt) {
angka+=”9″; //untuk button 9
txtLayar.setText(angka);

}

private void btnexitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);  //untuk button exit
}

private void btnpersenActionPerformed(java.awt.event.ActionEvent evt) {
bilanganSatu = Double.parseDouble(angka);
txtLayar.setText(“%”); //untuk button %
angka =””;
pilihan =5;

}

Semoga bermanfaat…..

8 Comments Add yours

  1. samuel mengatakan:

    terima kasih

  2. Hershel mengatakan:

    This website was… how do I say it? Relevant!! Finally I’ve found something that helped me. Thanks!

  3. I think the admin of this web site is really working hard in support of his web site, for the reason
    that here every data is quality based stuff.

  4. I enjoy looking through an article that will make people think.
    Also, many thanks for permitting me to comment!

  5. clean car rims mengatakan:

    When I initially commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment
    is added I receive 4 emails with the exact same comment.
    Is there a way you are able to remove me from that service?
    Kudos!

  6. You do not look for them but you attract them and they seek you out.
    BIG CARP FLAVOURS FEEDING TRIGGERS AND CARP SENSES EXPLOITATION SECRETS.
    When one of the committee members explains something or poses a question,
    keep looking at this person for as long as he or she
    is speaking.

  7. Forrest mengatakan:

    Hurrah! At last I got a web site from where I
    can in fact obtain valuable data regarding my study and knowledge.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s