/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulatorrr;
import javax.swing.JOptionPane;
/**
*
* @author boneng
*/
public class CL extends javax.swing.JFrame {
int pilih;
double angka1, angka2, hasil;
String angka;
/**
* Creates new form CL
*/
public CL() {
initComponents();
angka="";
buttonGroup1.add(rt);
buttonGroup1.add(rt1);
}
/**
* 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() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
buttonGroup3 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
output = new javax.swing.JTextField();
nol = new javax.swing.JButton();
satu = new javax.swing.JButton();
tiga = new javax.swing.JButton();
dua = new javax.swing.JButton();
enam = new javax.swing.JButton();
tujuh = new javax.swing.JButton();
empat = new javax.swing.JButton();
lima = new javax.swing.JButton();
smbilan = new javax.swing.JButton();
dlapan = new javax.swing.JButton();
samadengan = new javax.swing.JButton();
C = new javax.swing.JButton();
A = new javax.swing.JButton();
B = new javax.swing.JButton();
Cdes = new javax.swing.JButton();
D = new javax.swing.JButton();
E = new javax.swing.JButton();
biner = new javax.swing.JRadioButton();
kali = new javax.swing.JButton();
kurang = new javax.swing.JButton();
tambah = new javax.swing.JButton();
desimal = new javax.swing.JRadioButton();
bagi = new javax.swing.JButton();
oktal = new javax.swing.JRadioButton();
hexa = new javax.swing.JRadioButton();
mod = new javax.swing.JButton();
rt = new javax.swing.JRadioButton();
rt1 = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(51, 51, 51));
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.white, java.awt.Color.darkGray, java.awt.Color.gray));
jLabel1.setFont(new java.awt.Font("Base 02", 0, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("KALKULATOR ");
output.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
outputActionPerformed(evt);
}
});
nol.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
nol.setText("0");
nol.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nolActionPerformed(evt);
}
});
satu.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
satu.setText("1");
satu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
satuActionPerformed(evt);
}
});
tiga.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
tiga.setText("3");
tiga.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tigaActionPerformed(evt);
}
});
dua.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
dua.setText("2");
dua.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
duaActionPerformed(evt);
}
});
enam.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
enam.setText("6");
enam.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enamActionPerformed(evt);
}
});
tujuh.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
tujuh.setText("7");
tujuh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tujuhActionPerformed(evt);
}
});
empat.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
empat.setText("4");
empat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
empatActionPerformed(evt);
}
});
lima.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
lima.setText("5");
lima.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
limaActionPerformed(evt);
}
});
smbilan.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
smbilan.setText("9");
smbilan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
smbilanActionPerformed(evt);
}
});
dlapan.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
dlapan.setText("8");
dlapan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dlapanActionPerformed(evt);
}
});
samadengan.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
samadengan.setText("=");
samadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
samadenganActionPerformed(evt);
}
});
C.setFont(new java.awt.Font("Arial Black", 1, 18)); // NOI18N
C.setText("C");
C.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CActionPerformed(evt);
}
});
A.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
A.setText("A");
A.setEnabled(false);
A.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AActionPerformed(evt);
}
});
B.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
B.setText("B");
B.setEnabled(false);
B.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BActionPerformed(evt);
}
});
Cdes.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
Cdes.setText("C");
Cdes.setEnabled(false);
Cdes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CdesActionPerformed(evt);
}
});
D.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
D.setText("D");
D.setEnabled(false);
D.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DActionPerformed(evt);
}
});
E.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
E.setText("E");
E.setEnabled(false);
E.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EActionPerformed(evt);
}
});
biner.setBackground(new java.awt.Color(51, 51, 51));
buttonGroup1.add(biner);
biner.setFont(new java.awt.Font("ChorusLineSSi", 0, 14)); // NOI18N
biner.setForeground(new java.awt.Color(255, 255, 255));
biner.setText("Biner");
biner.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
biner.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binerActionPerformed(evt);
}
});
kali.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
kali.setText("*");
kali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kaliActionPerformed(evt);
}
});
kurang.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
kurang.setText("-");
kurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kurangActionPerformed(evt);
}
});
tambah.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
tambah.setText("+");
tambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tambahActionPerformed(evt);
}
});
desimal.setBackground(new java.awt.Color(51, 51, 51));
buttonGroup1.add(desimal);
desimal.setFont(new java.awt.Font("ChorusLineSSi", 0, 14)); // NOI18N
desimal.setForeground(new java.awt.Color(255, 255, 255));
desimal.setText("Desimal");
desimal.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
bagi.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
bagi.setText("/");
bagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bagiActionPerformed(evt);
}
});
oktal.setBackground(new java.awt.Color(51, 51, 51));
buttonGroup1.add(oktal);
oktal.setFont(new java.awt.Font("ChorusLineSSi", 0, 14)); // NOI18N
oktal.setForeground(new java.awt.Color(255, 255, 255));
oktal.setText("Oktal");
oktal.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
oktal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oktalActionPerformed(evt);
}
});
hexa.setBackground(new java.awt.Color(51, 51, 51));
buttonGroup1.add(hexa);
hexa.setFont(new java.awt.Font("ChorusLineSSi", 0, 14)); // NOI18N
hexa.setForeground(new java.awt.Color(255, 255, 255));
hexa.setText("Hexa");
hexa.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
hexa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hexaActionPerformed(evt);
}
});
mod.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
mod.setText("%");
mod.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modActionPerformed(evt);
}
});
rt.setText("biner to desimal");
rt.setOpaque(false);
rt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rtActionPerformed(evt);
}
});
rt1.setText("hexa to desimal");
rt1.setOpaque(false);
rt1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rt1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(151, 151, 151)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(73, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(dua, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nol, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(satu, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tiga, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(empat, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(lima, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(enam, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(tujuh, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(dlapan, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(smbilan, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(B, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(A, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Cdes, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(D, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(E, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(57, 57, 57)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(tambah, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(kurang, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(oktal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(biner, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(desimal)
.addComponent(hexa)))
.addComponent(rt1)
.addComponent(rt)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(mod, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(C, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(kali, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(bagi, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(output, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(samadengan, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(36, 36, 36))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(output, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(samadengan, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nol, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(satu, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(A, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(dua, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tiga, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(B, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(empat, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lima, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Cdes, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(enam, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tujuh, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(D, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(dlapan, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(smbilan, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(E, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tambah, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(kurang, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(kali, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bagi, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(C, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(mod, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(2, 2, 2)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(biner)
.addComponent(hexa))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(desimal)
.addComponent(oktal, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rt)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, Short.MAX_VALUE)
.addComponent(rt1)))
.addGap(65, 65, 65))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>
private void outputActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void nolActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="0";
output.setText(angka);
}
private void satuActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="1";
output.setText(angka);
}
private void duaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="2";
output.setText(angka);
}
private void tigaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="3";
output.setText(angka);
}
private void empatActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="4";
output.setText(angka);
}
private void limaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="5";
output.setText(angka);
}
private void enamActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="6";
output.setText(angka);
}
private void tujuhActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="7";
output.setText(angka);
}
private void dlapanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="8";
output.setText(angka);
}
private void smbilanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="9";
output.setText(angka);
}
private void tambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1= Double.parseDouble(angka);
angka="";
pilih = 1;
}
private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch (pilih){
case 1:
angka2 = Double.parseDouble(angka);
hasil= angka1 + angka2 ;
angka = Double.toString(hasil);
output.setText(angka);
break;
case 2:
angka2 = Double.parseDouble(angka);
hasil = angka1 - angka2;
angka = Double.toString(hasil);
output.setText(angka);
break;
case 3:
angka2= Double.parseDouble(angka);
hasil = angka1 * angka2;
angka = Double.toString(hasil);
output.setText(angka);
break;
case 4:
angka2 = Double.parseDouble(angka);
hasil = angka1 / angka2;
angka = Double.toString(hasil);
output.setText(angka);
break;
case 5:
String ip=output.getText();
output.setText(Integer.toBinaryString(Integer.parseInt(ip))); //Desimal to BIner
break;
case 6:
String ip2=output.getText();
output.setText(Debiner(ip2));
break;
case 7:
String ip3=output.getText();
output.setText(Hexa(Integer.parseInt(ip3)));
break;
case 8:
String ip4=output.getText();
output.setText(""+dehexa(ip4));
break;
case 9:
output.setText(""+Integer.toOctalString(Integer.parseInt(output.getText())));
break;
case 10:
angka2 = Double.parseDouble(angka);
hasil = angka1 % angka2;
angka = Double.toString(hasil);
output.setText(angka);
break;
default:
break;
}
}
String bilanganHexa(int desimal){
int a=desimal%16;
if(a==10)
return "A";
else if (a==11)
return "B";
else if (a==12)
return "C";
else if (a==13)
return "D";
else if (a==14)
return "E";
else if (a==15)
return "F";
else if (a==16)
return "G";
else
return ""+a;
}
String bilanganHexa(String desimal){
if(desimal.equalsIgnoreCase("A"))
desimal="10";
else if(desimal.equalsIgnoreCase("B"))
desimal= "11";
else if(desimal.equalsIgnoreCase("C"))
desimal= "12";
else if(desimal.equalsIgnoreCase("D"))
desimal= "13";
else if(desimal.equalsIgnoreCase("E"))
desimal= "14";
else if(desimal.equalsIgnoreCase("F"))
desimal= "15";
else if(desimal.equalsIgnoreCase("G"))
desimal= "16";
else
desimal=desimal;
return desimal;
}
String Hexa(int hex){
String hasil="";
hasil +=bilanganHexa(hex);
while(true){
if(hex>1){
hex /=16;
hasil +=bilanganHexa(hex);
} else {
break;
}
}
String a="";
for (int i = hasil.length(); i >0; i--) {
a +=hasil.charAt(i-1);
}
return a;
}
int dehexa(String Desimal){
int hasil=0;
for (int i = 0; i < Desimal.length(); i++) {
hasil +=Integer.parseInt(bilanganHexa(""+Desimal.charAt((Desimal.length()-1)-i)))*(Math.pow(16, i));
}
return hasil;
}
String Debiner(String debiner){
int hasil=0;int pangkat=0;
for (int i = debiner.length(); i > 0; i--) {
if(debiner.charAt(i-1)=='1' || debiner.charAt(i-1)=='0'){
String a=""+debiner.charAt(i-1);
hasil +=Integer.parseInt(a) * (int)(Math.pow(2, pangkat));
pangkat++;
}
}
return ""+hasil;
}
private void kurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
angka="";
pilih=2;
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
angka="";
pilih=3;
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
angka="";
pilih=4;
}
private void CActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=0;
angka2=0;
hasil=0;
angka="0";
output.setText("");
}
private void AActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="A";
output.setText(angka);
}
private void BActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="B";
output.setText(angka);
}
private void CdesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="C";
output.setText(angka);
}
private void DActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="D";
output.setText(angka);
}
private void EActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="E";
output.setText(angka);
}
private void binerActionPerformed(java.awt.event.ActionEvent evt) {
pilih=5 ;
}
private void oktalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pilih=9;
}
private void rtActionPerformed(java.awt.event.ActionEvent evt) {
pilih=6; // TODO add your handling code here:
}
private void hexaActionPerformed(java.awt.event.ActionEvent evt) {
pilih=7; // TODO add your handling code here:
}
private void rt1ActionPerformed(java.awt.event.ActionEvent evt) {
pilih=8;
A.setEnabled(true);
B.setEnabled(true);
C.setEnabled(true);
D.setEnabled(true);
E.setEnabled(true);
Cdes.setEnabled(true);
// TODO add your handling code here:
}
private void modActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
angka="";
pilih=10;
}
/**
* @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(CL.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CL.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CL.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CL.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CL().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton A;
private javax.swing.JButton B;
private javax.swing.JButton C;
private javax.swing.JButton Cdes;
private javax.swing.JButton D;
private javax.swing.JButton E;
private javax.swing.JButton bagi;
private javax.swing.JRadioButton biner;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.ButtonGroup buttonGroup3;
private javax.swing.JRadioButton desimal;
private javax.swing.JButton dlapan;
private javax.swing.JButton dua;
private javax.swing.JButton empat;
private javax.swing.JButton enam;
private javax.swing.JRadioButton hexa;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton kali;
private javax.swing.JButton kurang;
private javax.swing.JButton lima;
private javax.swing.JButton mod;
private javax.swing.JButton nol;
private javax.swing.JRadioButton oktal;
private javax.swing.JTextField output;
private javax.swing.JRadioButton rt;
private javax.swing.JRadioButton rt1;
private javax.swing.JButton samadengan;
private javax.swing.JButton satu;
private javax.swing.JButton smbilan;
private javax.swing.JButton tambah;
private javax.swing.JButton tiga;
private javax.swing.JButton tujuh;
// End of variables declaration
}
Posted by 22.28 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar