Created
January 16, 2017 08:19
-
-
Save griajobag/9a3c7a6e326890a488f3c1630347cbcd to your computer and use it in GitHub Desktop.
kalkulator sederhana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 education; | |
import java.util.*; | |
/** | |
* | |
* @author putuguna | |
*/ | |
public class SimpleCalculator extends javax.swing.JFrame { | |
public String FirstNumber; | |
public String secondNumber; | |
public List<Integer> listFirstNumber = new ArrayList<>(); | |
public List<Integer> listSecondNumber = new ArrayList<>(); | |
public boolean hasChooseAnOperation = false; | |
public int operation; | |
public SimpleCalculator() { | |
initComponents(); | |
this.setLocationRelativeTo(null); | |
} | |
/** | |
* 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() { | |
btnSatu = new javax.swing.JButton(); | |
btnDua = new javax.swing.JButton(); | |
btnTiga = new javax.swing.JButton(); | |
btnEmpat = new javax.swing.JButton(); | |
btnLima = new javax.swing.JButton(); | |
btnEnam = new javax.swing.JButton(); | |
btnTujuh = new javax.swing.JButton(); | |
btnDelapan = new javax.swing.JButton(); | |
btnSimbilan = new javax.swing.JButton(); | |
btnNol = new javax.swing.JButton(); | |
btnC = new javax.swing.JButton(); | |
btnSamaDengan = new javax.swing.JButton(); | |
btnTambah = new javax.swing.JButton(); | |
btnKurang = new javax.swing.JButton(); | |
btnKali = new javax.swing.JButton(); | |
btnBagi = new javax.swing.JButton(); | |
jLabel1 = new javax.swing.JLabel(); | |
lblAngkaPertama = new javax.swing.JLabel(); | |
lblOperasi = new javax.swing.JLabel(); | |
lblAngkaKedua = new javax.swing.JLabel(); | |
jLabel2 = new javax.swing.JLabel(); | |
lblHasil = new javax.swing.JLabel(); | |
jLabel3 = new javax.swing.JLabel(); | |
btnDeleteLastNumber = new javax.swing.JButton(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
btnSatu.setText("1"); | |
btnSatu.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnSatuActionPerformed(evt); | |
} | |
}); | |
btnDua.setText("2"); | |
btnDua.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnDuaActionPerformed(evt); | |
} | |
}); | |
btnTiga.setText("3"); | |
btnTiga.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnTigaActionPerformed(evt); | |
} | |
}); | |
btnEmpat.setText("4"); | |
btnEmpat.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnEmpatActionPerformed(evt); | |
} | |
}); | |
btnLima.setText("5"); | |
btnLima.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnLimaActionPerformed(evt); | |
} | |
}); | |
btnEnam.setText("6"); | |
btnEnam.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnEnamActionPerformed(evt); | |
} | |
}); | |
btnTujuh.setText("7"); | |
btnTujuh.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnTujuhActionPerformed(evt); | |
} | |
}); | |
btnDelapan.setText("8"); | |
btnDelapan.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnDelapanActionPerformed(evt); | |
} | |
}); | |
btnSimbilan.setText("9"); | |
btnSimbilan.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnSimbilanActionPerformed(evt); | |
} | |
}); | |
btnNol.setText("0"); | |
btnNol.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnNolActionPerformed(evt); | |
} | |
}); | |
btnC.setText("c"); | |
btnC.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnCActionPerformed(evt); | |
} | |
}); | |
btnSamaDengan.setText("="); | |
btnSamaDengan.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnSamaDenganActionPerformed(evt); | |
} | |
}); | |
btnTambah.setText("+"); | |
btnTambah.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnTambahActionPerformed(evt); | |
} | |
}); | |
btnKurang.setText("-"); | |
btnKurang.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnKurangActionPerformed(evt); | |
} | |
}); | |
btnKali.setText("*"); | |
btnKali.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnKaliActionPerformed(evt); | |
} | |
}); | |
btnBagi.setText("/"); | |
btnBagi.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnBagiActionPerformed(evt); | |
} | |
}); | |
jLabel1.setFont(new java.awt.Font("Arial Black", 1, 15)); // NOI18N | |
jLabel1.setText("KALKULATOR SEDERHANA"); | |
lblAngkaPertama.setText("Angka Pertama"); | |
lblOperasi.setText("Operasi"); | |
lblAngkaKedua.setText("Angka Kedua"); | |
jLabel2.setText("Hasilnya : "); | |
lblHasil.setText("0"); | |
jLabel3.setFont(new java.awt.Font("Arial Black", 1, 15)); // NOI18N | |
jLabel3.setText("www.putuguna.com"); | |
btnDeleteLastNumber.setText("DEL"); | |
btnDeleteLastNumber.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnDeleteLastNumberActionPerformed(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() | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(40, 40, 40) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(layout.createSequentialGroup() | |
.addComponent(btnTujuh, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnDelapan, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnSimbilan, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnKali, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addGroup(layout.createSequentialGroup() | |
.addComponent(btnEmpat, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnLima, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnEnam, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnKurang, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))) | |
.addGap(27, 27, 27) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(lblAngkaKedua) | |
.addComponent(lblOperasi))) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(40, 40, 40) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() | |
.addComponent(btnSatu, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnDua, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnTiga, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnTambah, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(27, 27, 27)) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(layout.createSequentialGroup() | |
.addComponent(btnNol, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnC, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addComponent(btnDeleteLastNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnSamaDengan, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnBagi, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(24, 24, 24))) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addComponent(jLabel2) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(lblHasil)) | |
.addComponent(lblAngkaPertama))) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(131, 131, 131) | |
.addComponent(jLabel3)) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(84, 84, 84) | |
.addComponent(jLabel1))) | |
.addContainerGap(75, Short.MAX_VALUE)) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(21, 21, 21) | |
.addComponent(jLabel1) | |
.addGap(18, 18, 18) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(btnSatu) | |
.addComponent(btnDua) | |
.addComponent(btnTiga) | |
.addComponent(btnTambah) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(6, 6, 6) | |
.addComponent(lblAngkaPertama))) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(6, 6, 6) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(btnEmpat) | |
.addComponent(btnLima) | |
.addComponent(btnEnam) | |
.addComponent(btnKurang)) | |
.addGap(6, 6, 6) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(btnTujuh) | |
.addComponent(btnDelapan) | |
.addComponent(btnSimbilan) | |
.addComponent(btnKali))) | |
.addGroup(layout.createSequentialGroup() | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(lblOperasi) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(lblAngkaKedua))) | |
.addGap(6, 6, 6) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(btnC) | |
.addComponent(btnNol)) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(btnSamaDengan) | |
.addComponent(btnBagi) | |
.addComponent(jLabel2) | |
.addComponent(lblHasil))) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(btnDeleteLastNumber) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(jLabel3) | |
.addGap(21, 21, 21)) | |
); | |
pack(); | |
}// </editor-fold> | |
private void btnCActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
lblAngkaKedua.setText("Angka Pertama"); | |
lblAngkaPertama.setText("Angka Kedua"); | |
lblHasil.setText("0"); | |
lblOperasi.setText("Operasi"); | |
hasChooseAnOperation=false; | |
listFirstNumber.clear(); | |
listSecondNumber.clear(); | |
} | |
private void btnSamaDenganActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
int total = 0; | |
double totalPembagian = 0; | |
switch (operation) { | |
case 0: | |
String firstTotalPertambahan = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
firstTotalPertambahan += listFirstNumber.get(i); | |
System.out.println(firstTotalPertambahan); | |
} | |
String secondTotalPertambahan = ""; | |
for(int j=0; j<listSecondNumber.size(); j++){ | |
secondTotalPertambahan += listSecondNumber.get(j); | |
} | |
total = Integer.parseInt(firstTotalPertambahan)+Integer.parseInt(secondTotalPertambahan); | |
// print the result to JLabel | |
lblHasil.setText(total+""); | |
//set the label to default | |
lblAngkaKedua.setText("Angka Pertama"); | |
lblAngkaPertama.setText("Angka Kedua"); | |
lblOperasi.setText("Operasi"); | |
//set false. | |
hasChooseAnOperation = false; | |
//clear the list | |
listFirstNumber.clear(); | |
listSecondNumber.clear(); | |
break; | |
case 1: | |
String firstTotalPeNgurangan = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
firstTotalPeNgurangan += listFirstNumber.get(i); | |
System.out.println(firstTotalPeNgurangan); | |
} | |
String secondTotalPengurangan = ""; | |
for(int j=0; j<listSecondNumber.size(); j++){ | |
secondTotalPengurangan += listSecondNumber.get(j); | |
} | |
total = Integer.parseInt(firstTotalPeNgurangan)-Integer.parseInt(secondTotalPengurangan); | |
// print the result to JLabel | |
lblHasil.setText(total+""); | |
//set the label to default | |
lblAngkaKedua.setText("Angka Pertama"); | |
lblAngkaPertama.setText("Angka Kedua"); | |
lblOperasi.setText("Operasi"); | |
//set false. | |
hasChooseAnOperation = false; | |
//clear the list | |
listFirstNumber.clear(); | |
listSecondNumber.clear(); | |
break; | |
case 2: | |
String firstTotalPerkalian = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
firstTotalPerkalian += listFirstNumber.get(i); | |
System.out.println(firstTotalPerkalian); | |
} | |
String secondTotalPerkalian = ""; | |
for(int j=0; j<listSecondNumber.size(); j++){ | |
secondTotalPerkalian += listSecondNumber.get(j); | |
} | |
total = Integer.parseInt(firstTotalPerkalian)*Integer.parseInt(secondTotalPerkalian); | |
// print the result to JLabel | |
lblHasil.setText(total+""); | |
//set the label to default | |
lblAngkaKedua.setText("Angka Pertama"); | |
lblAngkaPertama.setText("Angka Kedua"); | |
lblOperasi.setText("Operasi"); | |
//set false. | |
hasChooseAnOperation = false; | |
//clear the list | |
listFirstNumber.clear(); | |
listSecondNumber.clear(); | |
break; | |
case 3: | |
String firstTotalPembagian = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
firstTotalPembagian += listFirstNumber.get(i); | |
System.out.println(firstTotalPembagian); | |
} | |
String secondTotalPembagian = ""; | |
for(int j=0; j<listSecondNumber.size(); j++){ | |
secondTotalPembagian += listSecondNumber.get(j); | |
} | |
totalPembagian = Double.parseDouble(firstTotalPembagian)/Double.parseDouble(secondTotalPembagian); | |
//set the label to default | |
lblAngkaKedua.setText("Angka Pertama"); | |
lblAngkaPertama.setText("Angka Kedua"); | |
lblOperasi.setText("Operasi"); | |
//print the result to JLabel | |
lblHasil.setText(String.format("%.6f%n", totalPembagian)); | |
//set false. | |
hasChooseAnOperation = false; | |
//clear the list | |
listFirstNumber.clear(); | |
listSecondNumber.clear(); | |
break; | |
default: | |
break; | |
} | |
} | |
private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
operation = 0; | |
lblOperasi.setText("+"); | |
hasChooseAnOperation =true; | |
} | |
private void btnKurangActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
operation = 1; | |
lblOperasi.setText("-"); | |
hasChooseAnOperation =true; | |
} | |
private void btnKaliActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
operation = 2; | |
lblOperasi.setText("*"); | |
hasChooseAnOperation =true; | |
} | |
private void btnBagiActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
operation = 3; | |
lblOperasi.setText("/"); | |
hasChooseAnOperation =true; | |
//http://stackoverflow.com/a/6166811/3934214 | |
} | |
private void btnTujuhActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "7"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "7"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnDelapanActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "8"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "8"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnSimbilanActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "9"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "9"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnSatuActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "1"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "1"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnDuaActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "2"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "2"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnTigaActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "3"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "3"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnEmpatActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "4"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "4"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnLimaActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "5"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "5"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnEnamActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "6"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "6"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnDeleteLastNumberActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
listFirstNumber.remove(listFirstNumber.size()-1); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
listSecondNumber.remove(listSecondNumber.size()-1); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
private void btnNolActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
if(hasChooseAnOperation==false){ | |
FirstNumber = "0"; | |
listFirstNumber.add(Integer.parseInt(FirstNumber)); | |
String digitFistNumber = ""; | |
for(int i=0; i<listFirstNumber.size(); i++){ | |
digitFistNumber += listFirstNumber.get(i); | |
lblAngkaPertama.setText(digitFistNumber); | |
} | |
}else{ | |
secondNumber = "0"; | |
listSecondNumber.add(Integer.parseInt(secondNumber)); | |
String digitSecondNumber = ""; | |
for(int i=0; i<listSecondNumber.size(); i++){ | |
digitSecondNumber += listSecondNumber.get(i); | |
lblAngkaKedua.setText(digitSecondNumber); | |
} | |
} | |
} | |
/** | |
* @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(SimpleCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(SimpleCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(SimpleCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(SimpleCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new SimpleCalculator().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JButton btnBagi; | |
private javax.swing.JButton btnC; | |
private javax.swing.JButton btnDelapan; | |
private javax.swing.JButton btnDeleteLastNumber; | |
private javax.swing.JButton btnDua; | |
private javax.swing.JButton btnEmpat; | |
private javax.swing.JButton btnEnam; | |
private javax.swing.JButton btnKali; | |
private javax.swing.JButton btnKurang; | |
private javax.swing.JButton btnLima; | |
private javax.swing.JButton btnNol; | |
private javax.swing.JButton btnSamaDengan; | |
private javax.swing.JButton btnSatu; | |
private javax.swing.JButton btnSimbilan; | |
private javax.swing.JButton btnTambah; | |
private javax.swing.JButton btnTiga; | |
private javax.swing.JButton btnTujuh; | |
private javax.swing.JLabel jLabel1; | |
private javax.swing.JLabel jLabel2; | |
private javax.swing.JLabel jLabel3; | |
private javax.swing.JLabel lblAngkaKedua; | |
private javax.swing.JLabel lblAngkaPertama; | |
private javax.swing.JLabel lblHasil; | |
private javax.swing.JLabel lblOperasi; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment