Program Calculator menggunakan Java

public class Kalkulator extends javax.swing.JFrame {
String angka;
Double total,angka1,angka2;
int pilih;
/** Creates new form Kalkulator */
public Kalkulator() {
super (“Kalkulator Sederhana”);
initComponents();
angka=””;
}
private void cmd0ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”0″;
tampil.setText(“0”);
}
private void tampilActionPerformed(java.awt.event.ActionEvent evt) {
}
private void cmd1ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”1″;
tampil.setText(“1″);
}
private void cmd2ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”2”;
tampil.setText(“2”);
}
private void cmd3ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”3″;
tampil.setText(“3″);
}
private void cmd4ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”4”;
tampil.setText(“4″);
}
private void cmd5ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”5”;
tampil.setText(“5”);
}
private void cmd6ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”6″;
tampil.setText(“6″);
}
private void cmd7ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”7”;
tampil.setText(“7″);
}
private void cmd8ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”8”;
tampil.setText(“8″);
}
private void cmd9ActionPerformed(java.awt.event.ActionEvent evt) {
angka +=”9”;
tampil.setText(“9”);
}
angka1=Double.parseDouble(angka);
tampil.setText(“+”);
angka=””;
pilih=1;
}
private void cmdkurangActionPerformed(java.awt.event.ActionEvent evt) {
angka1=Double.parseDouble(angka);
tampil.setText(“-“);
angka=””;
pilih=2;
}
private void cmdkaliActionPerformed(java.awt.event.ActionEvent evt) {
angka1=Double.parseDouble(angka);
tampil.setText(“*”);
angka=””;
pilih=3;
}
private void cmdhasilActionPerformed(java.awt.event.ActionEvent evt) {
switch(pilih)
{
case 1:
angka2=Double.parseDouble(angka);
total= angka1 + angka2;
angka=Double.toString(total);
tampil.setText(angka);
break;
case 2:
angka2=Double.parseDouble(angka);
total=angka1-angka2;
angka=Double.toString(total);
tampil.setText(angka);
break;
case 3:
angka2=Double.parseDouble(angka);
total=angka1*angka2;
angka=Double.toString(total);
tampil.setText(angka);
break;
default:
break;
}
}
private void cmdbersihActionPerformed(java.awt.event.ActionEvent evt) {
angka1=0.0;
angka2=0.0;
total=0.0;
angka=””;
tampil.setText(“”);
}

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

%d blogger menyukai ini: