2012420080
PAGI
public class kalculator extends javax.swing.JFrame {
public kalculator() {
initComponents();
setTitle("KALCULATOR YOMAN by GENTHONK");
hasil.setHorizontalAlignment(JTextField.RIGHT);
}
@SuppressWarnings("unchecked")
boolean mulaibaru ,koma1 , nollagi;
double nilai1,nilai2,hasil1,plusminus;
int proses , hasilint;
String operasi="des",operasi1="";
void yoman(){
try{
String mon = hasil.getText();
if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("des")){
hasil.setText(""+Integer.parseInt(mon,2));
operasi="des";
}
else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,2);
hasil.setText(""+Integer.toOctalString(a));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,2);
hasil.setText(""+Integer.toHexString(a));
operasi="hex";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,8);
hasil.setText(""+a);
operasi="des";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,8);
hasil.setText(""+Integer.toBinaryString(a));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,8);
hasil.setText(""+Integer.toHexString(a));
operasi="hex";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,16);
hasil.setText(""+a);
operasi="des";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,16);
hasil.setText(""+Integer.toBinaryString(a));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,16);
hasil.setText(""+Integer.toOctalString(a));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("bin")){
hasil.setText(""+Integer.toBinaryString(Integer.parseInt(mon)));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("okt")){
hasil.setText(""+Integer.toOctalString(Integer.parseInt(mon)));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("hex")){
hasil.setText(""+Integer.toHexString(Integer.parseInt(mon)));
operasi="hex";
}
}catch(NumberFormatException ab){
hasil.setText("error");
}
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
nol = new javax.swing.JButton();
enam = new javax.swing.JButton();
sembilan = new javax.swing.JButton();
hapus = new javax.swing.JButton();
koma = new javax.swing.JButton();
tiga = new javax.swing.JButton();
dua = new javax.swing.JButton();
tujuh = new javax.swing.JButton();
empat = new javax.swing.JButton();
satu = new javax.swing.JButton();
delapan = new javax.swing.JButton();
lima = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
biner = new javax.swing.JRadioButton();
hexa = new javax.swing.JRadioButton();
decimal = new javax.swing.JRadioButton();
octal = new javax.swing.JRadioButton();
jPanel4 = new javax.swing.JPanel();
samadengan = new javax.swing.JButton();
penjumlahan = new javax.swing.JButton();
min = new javax.swing.JButton();
pembagian = new javax.swing.JButton();
perkalian = new javax.swing.JButton();
pengurangan = new javax.swing.JButton();
modulus = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
e = new javax.swing.JButton();
f = new javax.swing.JButton();
a = new javax.swing.JButton();
b = new javax.swing.JButton();
c = new javax.swing.JButton();
d = new javax.swing.JButton();
jPanel6 = new javax.swing.JPanel();
hasil = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(51, 51, 51));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(102, 102, 102)));
jPanel2.setBackground(new java.awt.Color(102, 102, 102));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(51, 51, 51)));
nol.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
nol.setText("0");
nol.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
nol.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nolActionPerformed(evt);
}
});
enam.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
enam.setText("6");
enam.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
enam.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enamActionPerformed(evt);
}
});
sembilan.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
sembilan.setText("9");
sembilan.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
sembilan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sembilanActionPerformed(evt);
}
});
hapus.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
hapus.setForeground(new java.awt.Color(255, 0, 0));
hapus.setText("C");
hapus.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
hapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hapusActionPerformed(evt);
}
});
koma.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
koma.setText(".");
koma.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
koma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
komaActionPerformed(evt);
}
});
tiga.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
tiga.setText("3");
tiga.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
tiga.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tigaActionPerformed(evt);
}
});
dua.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
dua.setText("2");
dua.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
dua.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
duaActionPerformed(evt);
}
});
tujuh.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
tujuh.setText("7");
tujuh.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
tujuh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tujuhActionPerformed(evt);
}
});
empat.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
empat.setText("4");
empat.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
empat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
empatActionPerformed(evt);
}
});
satu.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
satu.setText("1");
satu.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
satu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
satuActionPerformed(evt);
}
});
delapan.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
delapan.setText("8");
delapan.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
delapan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
delapanActionPerformed(evt);
}
});
lima.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
lima.setText("5");
lima.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
lima.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
limaActionPerformed(evt);
}
});
jButton2.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
jButton2.setText("00\n");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tujuh)
.addComponent(hapus))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, 0, 0, Short.MAX_VALUE)
.addComponent(nol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(delapan))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(koma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(sembilan, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE))
.addGap(102, 102, 102))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(satu)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(dua)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(tiga))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(empat)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lima)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(enam))))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(satu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(dua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tiga, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(enam, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lima, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(empat, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tujuh, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
.addComponent(delapan, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
.addComponent(sembilan, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(koma, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(nol, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(hapus, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
.addContainerGap())
);
jPanel3.setBackground(new java.awt.Color(102, 102, 102));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
buttonGroup1.add(biner);
biner.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
biner.setText("BINER");
biner.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
biner.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binerActionPerformed(evt);
}
});
buttonGroup1.add(hexa);
hexa.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
hexa.setText("HEXA");
hexa.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
hexa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hexaActionPerformed(evt);
}
});
buttonGroup1.add(decimal);
decimal.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
decimal.setText("DEC");
decimal.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
decimal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decimalActionPerformed(evt);
}
});
buttonGroup1.add(octal);
octal.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
octal.setText("OCT");
octal.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
octal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
octalActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(decimal, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(octal, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(biner, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(hexa, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(hexa)
.addGap(18, 18, 18)
.addComponent(biner)
.addGap(11, 11, 11)
.addComponent(octal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
.addComponent(decimal)
.addContainerGap())
);
jPanel4.setBackground(new java.awt.Color(102, 102, 102));
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
samadengan.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
samadengan.setText("HASILLLLL");
samadengan.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
samadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
samadenganActionPerformed(evt);
}
});
penjumlahan.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
penjumlahan.setText("+");
penjumlahan.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
penjumlahan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
penjumlahanActionPerformed(evt);
}
});
min.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
min.setText("-/+");
min.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
min.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minActionPerformed(evt);
}
});
pembagian.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
pembagian.setText(":");
pembagian.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
pembagian.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pembagianActionPerformed(evt);
}
});
perkalian.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
perkalian.setText("x");
perkalian.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
perkalian.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
perkalianActionPerformed(evt);
}
});
pengurangan.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
pengurangan.setText("-");
pengurangan.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
pengurangan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
penguranganActionPerformed(evt);
}
});
modulus.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
modulus.setText("%");
modulus.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
modulus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modulusActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(samadengan, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(min, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
.addComponent(pengurangan, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
.addComponent(penjumlahan, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(modulus, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(perkalian, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pembagian, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)))))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(penjumlahan)
.addComponent(perkalian))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(pembagian)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(modulus))
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(pengurangan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(min)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(samadengan, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
.addContainerGap())
);
jPanel5.setBackground(new java.awt.Color(102, 102, 102));
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
e.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
e.setText("E");
e.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
e.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
eActionPerformed(evt);
}
});
f.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
f.setText("F");
f.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
f.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fActionPerformed(evt);
}
});
a.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
a.setText("A");
a.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
a.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aActionPerformed(evt);
}
});
b.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
b.setText("B");
b.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
b.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bActionPerformed(evt);
}
});
c.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
c.setText("C");
c.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
c.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cActionPerformed(evt);
}
});
d.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
d.setText("D");
d.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
d.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(13, Short.MAX_VALUE)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(a)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(b))
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(c)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(d))
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(e)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(f)))
.addContainerGap())
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(15, Short.MAX_VALUE)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(d, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(f, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(e, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel6.setBackground(new java.awt.Color(51, 51, 51));
jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel6.setForeground(new java.awt.Color(102, 102, 102));
hasil.setText("0");
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(hasil, javax.swing.GroupLayout.DEFAULT_SIZE, 552, Short.MAX_VALUE)
.addContainerGap())
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(hasil, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jButton1.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); // NOI18N
jButton1.setText("..............................EXIT..............................");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 576, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(29, 29, 29)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(153, 153, 153))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(60, 60, 60))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void penjumlahanActionPerformed(java.awt.event.ActionEvent evt) {
nilai1=Double.valueOf(hasil.getText());
mulaibaru=true;
proses=1;
}
private void minActionPerformed(java.awt.event.ActionEvent evt) {
plusminus=(Double.parseDouble(String.valueOf(hasil.getText())));plusminus=plusminus*(-1);hasil.setText(String.valueOf(plusminus));
}
private void satuActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("1");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+ "1");
}
}
private void duaActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("2");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"2");
}
}
private void tigaActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("3");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"3");
}
}
private void empatActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("4");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"4");
}
}
private void limaActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("5");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"5");
}
}
private void enamActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("6");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"6");
}
}
private void tujuhActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("7");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"7");
}
}
private void delapanActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("8");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"8");
}
}
private void sembilanActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("9");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"9");
}
}
private void nolActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("0");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+"0");
}
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText(".");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+".");
}
}
private void aActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("a");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+a.getText());
}
}
private void bActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("b");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+b.getText());
}}
private void cActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("c");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+c.getText());
}
}
private void dActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("d");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+d.getText());
}
}
private void eActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("e");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+e.getText());
}
}
private void decimalActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(true);
tiga.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(true);
sembilan.setEnabled(true);
nol.setEnabled(true);
a.setEnabled(false);
b.setEnabled(false);
c.setEnabled(false);
d.setEnabled(false);
e.setEnabled(false);
f.setEnabled(false);
operasi1="des";
yoman();
// TODO add your handling code here:
}
private void fActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(hasil.getText())) {
hasil.setText("");
}
if (mulaibaru) {
hasil.setText("f");
mulaibaru=false;
}else{
hasil.setText(hasil.getText()+f.getText());
}
}
private void binerActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(false);
tiga.setEnabled(false);
empat.setEnabled(false);
lima.setEnabled(false);
enam.setEnabled(false);
tujuh.setEnabled(false);
delapan.setEnabled(false);
sembilan.setEnabled(false);
nol.setEnabled(true);
a.setEnabled(false);
b.setEnabled(false);
c.setEnabled(false);
d.setEnabled(false);
e.setEnabled(false);
f.setEnabled(false);
operasi1="bin";
yoman();
}
private void hexaActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(true);
tiga.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(true);
sembilan.setEnabled(true);
nol.setEnabled(true);
a.setEnabled(true);
b.setEnabled(true);
c.setEnabled(true);
d.setEnabled(true);
e.setEnabled(true);
f.setEnabled(true);
operasi1="hex";
yoman();
}
private void octalActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(true);
tiga.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(false);
sembilan.setEnabled(false);
nol.setEnabled(false);
a.setEnabled(false);
b.setEnabled(false);
c.setEnabled(false);
d.setEnabled(false);
e.setEnabled(false);
f.setEnabled(false);
operasi1="okt";
yoman();
}
private void penguranganActionPerformed(java.awt.event.ActionEvent evt) {
nilai1=Double.valueOf(hasil.getText());
mulaibaru=true;
proses=2;
}
private void perkalianActionPerformed(java.awt.event.ActionEvent evt) {
nilai1=Double.valueOf(hasil.getText());
mulaibaru=true;
proses=3;
}
private void pembagianActionPerformed(java.awt.event.ActionEvent evt) {
nilai1=Double.valueOf(hasil.getText());
mulaibaru=true;
proses=4;
}
private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {
nilai2=Double.parseDouble(String.valueOf(hasil.getText()));
switch(proses){
case 1:
hasil1=nilai1+nilai2;
hasil.setText(String.valueOf(hasil1));
break;
case 2:
hasil1=nilai1-nilai2;
hasil.setText(String.valueOf(hasil1));
break;
case 3:
hasil1=nilai1*nilai2;
hasil.setText(String.valueOf(hasil1));
break;
case 4:
hasil1=nilai1/nilai2;
hasil.setText(String.valueOf(hasil1));
break;
case 5:
hasil1=nilai1%nilai2;
hasil.setText(String.valueOf(hasil1));
break;
default:
break;
}
mulaibaru=true;
koma1=false;
proses=0;
nilai1=0;
nilai2=0;
hasil1=0;
}
private void hapusActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText("");
}
private void modulusActionPerformed(java.awt.event.ActionEvent evt) {
nilai1=Double.valueOf(hasil.getText());
mulaibaru=true;
proses=5;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Posted by 14.06 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar