/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author pranata
*/
public class kalkulator extends javax.swing.JFrame {
String angka;
Integer jumlah,angka1,angka2;
int pilih;
/**
* Creates new form kalkulator
*/
public kalkulator() {
initComponents();
angka="";
}
/**
* 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();
jLabel1 = new javax.swing.JLabel();
oprhasil = new javax.swing.JTextField();
opr1 = new javax.swing.JButton();
opr2 = new javax.swing.JButton();
opr3 = new javax.swing.JButton();
opr4 = new javax.swing.JButton();
opr5 = new javax.swing.JButton();
opr6 = new javax.swing.JButton();
opr7 = new javax.swing.JButton();
opr8 = new javax.swing.JButton();
opr9 = new javax.swing.JButton();
opr0 = new javax.swing.JButton();
oprsamadengan = new javax.swing.JButton();
oprkali = new javax.swing.JButton();
oprbagi = new javax.swing.JButton();
oprtambah = new javax.swing.JButton();
oprkurang = new javax.swing.JButton();
oprclear = new javax.swing.JButton();
biner = new javax.swing.JRadioButton();
hexsa = new javax.swing.JRadioButton();
oktal = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(153, 255, 51));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setForeground(new java.awt.Color(102, 255, 51));
jLabel1.setText("Hitung");
oprhasil.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprhasilActionPerformed(evt);
}
});
opr1.setText("1");
opr1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr1ActionPerformed(evt);
}
});
opr2.setText("2");
opr2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr2ActionPerformed(evt);
}
});
opr3.setText("3");
opr3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr3ActionPerformed(evt);
}
});
opr4.setText("4");
opr4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr4ActionPerformed(evt);
}
});
opr5.setText("5");
opr5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr5ActionPerformed(evt);
}
});
opr6.setText("6");
opr6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr6ActionPerformed(evt);
}
});
opr7.setText("7");
opr7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr7ActionPerformed(evt);
}
});
opr8.setText("8");
opr8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr8ActionPerformed(evt);
}
});
opr9.setText("9");
opr9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr9ActionPerformed(evt);
}
});
opr0.setText("0");
opr0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opr0ActionPerformed(evt);
}
});
oprsamadengan.setText("=");
oprsamadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprsamadenganActionPerformed(evt);
}
});
oprkali.setText("x");
oprkali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprkaliActionPerformed(evt);
}
});
oprbagi.setText("/");
oprbagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprbagiActionPerformed(evt);
}
});
oprtambah.setText("+");
oprtambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprtambahActionPerformed(evt);
}
});
oprkurang.setText("-");
oprkurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprkurangActionPerformed(evt);
}
});
oprclear.setText("C");
oprclear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oprclearActionPerformed(evt);
}
});
buttonGroup1.add(biner);
biner.setText("biner");
biner.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binerActionPerformed(evt);
}
});
buttonGroup1.add(hexsa);
hexsa.setText("hex");
hexsa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hexsaActionPerformed(evt);
}
});
buttonGroup1.add(oktal);
oktal.setText("oktal");
oktal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oktalActionPerformed(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()
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(oprhasil, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(oprclear, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(biner)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(oktal)
.addGap(18, 18, 18)
.addComponent(hexsa))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(oprsamadengan, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(opr1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(opr5, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(opr9, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(opr3, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addComponent(opr2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(opr4, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(8, 8, 8)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(opr8, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(opr6, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(opr0, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(opr7, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(oprtambah, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(oprkali, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addComponent(oprbagi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(oprkurang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
.addContainerGap(11, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(oprhasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(opr1)
.addComponent(opr5)
.addComponent(opr9)
.addComponent(oprkali))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(opr2)
.addComponent(opr6)
.addComponent(opr0)
.addComponent(oprbagi))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(opr3)
.addComponent(opr7)
.addComponent(oprtambah)
.addComponent(oprkurang))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(oprsamadengan)
.addComponent(opr8)
.addComponent(opr4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(biner, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(hexsa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(oktal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(oprclear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(34, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void opr0ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="0";
oprhasil.setText(angka);
}
private void opr8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="8";
oprhasil.setText(angka);
}
private void oprkurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
oprhasil.setText("-");
angka="";
pilih=2;
}
private void opr1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="1";
oprhasil.setText(angka);
}
private void opr2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="2";
oprhasil.setText(angka);
}
private void opr3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="3";
oprhasil.setText(angka);
}
private void opr4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="4";
oprhasil.setText(angka);
}
private void opr5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="5";
oprhasil.setText(angka);
}
private void opr6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="6";
oprhasil.setText(angka);
}
private void opr7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="7";
oprhasil.setText(angka);
}
private void opr9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka +="9";
oprhasil.setText(angka);
}
private void oprtambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
oprhasil.setText("+");
angka="";
pilih=1;
}
private void oprsamadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch(pilih){
case 1:
angka2=Integer.parseInt(angka);
jumlah= angka1+angka2;
angka=Integer.toString(jumlah);
oprhasil.setText(angka);
break;
case 2:
angka2=Integer.parseInt(angka);
jumlah= angka1-angka2;
angka=Integer.toString(jumlah);
oprhasil.setText(angka);
break;
case 3:
angka2=Integer.parseInt(angka);
jumlah= angka1*angka2;
angka=Integer.toString(jumlah);
oprhasil.setText(angka);
break;
case 4:
angka2=Integer.parseInt(angka);
jumlah= angka1/angka2;
angka=Integer.toString(jumlah);
oprhasil.setText(angka);
break;
case 5:
int des = angka1;
String bin = Integer.toBinaryString(des);
angka= Integer.toString(angka1);
oprhasil.setText(bin);
break;
case 6:
int desi = angka1;
String hexsa = Integer.toHexString(desi);
angka=Integer.toString(angka1);
oprhasil.setText(hexsa);
case 7:
int desimal=angka1;
String octal=Integer.toOctalString(desimal);
angka=Integer.toString(angka1);
oprhasil.setText(octal);
default:
}
}
private void oprkaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
oprhasil.setText("*");
angka="";
pilih=3;
}
private void oprbagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
oprhasil.setText("/");
angka="";
pilih=4;
}
private void oprhasilActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void oprclearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=null;
angka2=null;
jumlah=null;
angka="";
oprhasil.setText("");
}
private void binerActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
angka="";
pilih=5;
}
private void hexsaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
angka="";
pilih=6;
}
private void oktalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Integer.parseInt(angka);
angka="";
pilih=7;
}
/**
* @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(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalkulator.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 kalkulator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JRadioButton biner;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JRadioButton hexsa;
private javax.swing.JLabel jLabel1;
private javax.swing.JRadioButton oktal;
private javax.swing.JButton opr0;
private javax.swing.JButton opr1;
private javax.swing.JButton opr2;
private javax.swing.JButton opr3;
private javax.swing.JButton opr4;
private javax.swing.JButton opr5;
private javax.swing.JButton opr6;
private javax.swing.JButton opr7;
private javax.swing.JButton opr8;
private javax.swing.JButton opr9;
private javax.swing.JButton oprbagi;
private javax.swing.JButton oprclear;
private javax.swing.JTextField oprhasil;
private javax.swing.JButton oprkali;
private javax.swing.JButton oprkurang;
private javax.swing.JButton oprsamadengan;
private javax.swing.JButton oprtambah;
// End of variables declaration
}
@2012420144
F. Handy Pranata.
Klas Pagi.
Posted by 20.14 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar