Tugas KALKULATOR....GAGUH SUKMA WANTOKO / 2012420019
import java.awt.HeadlessException;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author user
*/
public class kalkulator extends javax.swing.JFrame {
boolean koma,baru,clear;
public kalkulator() {
initComponents();
setTitle("KALKULATOR SEDERHANA");
area.setHorizontalAlignment(JTextField.RIGHT);
des.setSelected(true);
semb();
}
int tambah1;
int kurang1;
int kali1;
int bagi1;
int desimal;
int bin1;
int octal;
int hexa;
int modulus;
double angka1;
double angka2;
double total;
String operasi="des",operasi1="";
public void konversi(){
try{
String mon = area.getText();
if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("des")){
area.setText(""+Integer.parseInt(mon,2));
operasi="des";
}
else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,2);
area.setText(""+Integer.toOctalString(a));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,2);
area.setText(""+Integer.toHexString(a));
operasi="hex";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,8);
area.setText(""+a);
operasi="des";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,8);
area.setText(""+Integer.toBinaryString(a));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,8);
area.setText(""+Integer.toHexString(a));
operasi="hex";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,16);
area.setText(""+a);
operasi="des";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,16);
area.setText(""+Integer.toBinaryString(a));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,16);
area.setText(""+Integer.toOctalString(a));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("bin")){
area.setText(""+Integer.toBinaryString(Integer.parseInt(mon)));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("okt")){
area.setText(""+Integer.toOctalString(Integer.parseInt(mon)));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("hex")){
area.setText(""+Integer.toHexString(Integer.parseInt(mon)));
operasi="hex";
}
}catch(NumberFormatException ab){
area.setText("error");
}
}
public void semb(){
if (des.isSelected()){
satu.setEnabled(true);
dua.setEnabled(true);
tiga1.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(true);
sembilan.setEnabled(true);
nol.setEnabled(true);
A1.setEnabled(false);
B1.setEnabled(false);
C1.setEnabled(false);
D1.setEnabled(false);
E1.setEnabled(false);
F.setEnabled(false);
}
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
area = new javax.swing.JTextField();
satu = new javax.swing.JButton();
empat = new javax.swing.JButton();
dua = new javax.swing.JButton();
tiga1 = new javax.swing.JButton();
enam = new javax.swing.JButton();
lima = new javax.swing.JButton();
tujuh = new javax.swing.JButton();
delapan = new javax.swing.JButton();
sembilan = new javax.swing.JButton();
kurang = new javax.swing.JButton();
F = new javax.swing.JButton();
bagi = new javax.swing.JButton();
kali = new javax.swing.JButton();
samadengan1 = new javax.swing.JButton();
titik = new javax.swing.JButton();
nol = new javax.swing.JButton();
kurangtambah1 = new javax.swing.JButton();
hapus1 = new javax.swing.JButton();
tmbh1 = new javax.swing.JButton();
A1 = new javax.swing.JButton();
B1 = new javax.swing.JButton();
C1 = new javax.swing.JButton();
E1 = new javax.swing.JButton();
D1 = new javax.swing.JButton();
hapus2 = new javax.swing.JButton();
hex = new javax.swing.JRadioButton();
des = new javax.swing.JRadioButton();
bin = new javax.swing.JRadioButton();
oct = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(204, 204, 204));
jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
area.setEditable(false);
area.setBackground(new java.awt.Color(255, 255, 255));
area.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
area.setForeground(new java.awt.Color(51, 51, 51));
area.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.add(area, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 310, 46));
satu.setBackground(new java.awt.Color(204, 204, 204));
satu.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
satu.setText("1");
satu.setBorder(javax.swing.BorderFactory.createEtchedBorder());
satu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
satuActionPerformed(evt);
}
});
jPanel1.add(satu, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 44, 44));
empat.setBackground(new java.awt.Color(204, 204, 204));
empat.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
empat.setText("4");
empat.setBorder(javax.swing.BorderFactory.createEtchedBorder());
empat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
empatActionPerformed(evt);
}
});
jPanel1.add(empat, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 160, 44, 44));
dua.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
dua.setText("2");
dua.setBorder(javax.swing.BorderFactory.createEtchedBorder());
dua.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
duaActionPerformed(evt);
}
});
jPanel1.add(dua, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 110, 44, 44));
tiga1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
tiga1.setText("3");
tiga1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
tiga1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tiga1ActionPerformed(evt);
}
});
jPanel1.add(tiga1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 110, 44, 44));
enam.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
enam.setText("6");
enam.setBorder(javax.swing.BorderFactory.createEtchedBorder());
enam.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enamActionPerformed(evt);
}
});
jPanel1.add(enam, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 160, 44, 44));
lima.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
lima.setText("5");
lima.setBorder(javax.swing.BorderFactory.createEtchedBorder());
lima.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
limaActionPerformed(evt);
}
});
jPanel1.add(lima, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 160, 44, 44));
tujuh.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
tujuh.setText("7");
tujuh.setBorder(javax.swing.BorderFactory.createEtchedBorder());
tujuh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tujuhActionPerformed(evt);
}
});
jPanel1.add(tujuh, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, 44, 44));
delapan.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
delapan.setText("8");
delapan.setBorder(javax.swing.BorderFactory.createEtchedBorder());
delapan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
delapanActionPerformed(evt);
}
});
jPanel1.add(delapan, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 210, 44, 44));
sembilan.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
sembilan.setText("9");
sembilan.setBorder(javax.swing.BorderFactory.createEtchedBorder());
sembilan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sembilanActionPerformed(evt);
}
});
jPanel1.add(sembilan, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 210, 44, 44));
kurang.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
kurang.setText("-");
kurang.setBorder(javax.swing.BorderFactory.createEtchedBorder());
kurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kurangActionPerformed(evt);
}
});
jPanel1.add(kurang, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 160, 44, 44));
F.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
F.setText("F");
F.setBorder(javax.swing.BorderFactory.createEtchedBorder());
F.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FActionPerformed(evt);
}
});
jPanel1.add(F, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 210, 44, 44));
bagi.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
bagi.setText("/");
bagi.setBorder(javax.swing.BorderFactory.createEtchedBorder());
bagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bagiActionPerformed(evt);
}
});
jPanel1.add(bagi, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 260, 44, 44));
kali.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
kali.setText("*");
kali.setBorder(javax.swing.BorderFactory.createEtchedBorder());
kali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kaliActionPerformed(evt);
}
});
jPanel1.add(kali, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 210, 44, 44));
samadengan1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
samadengan1.setText("=");
samadengan1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
samadengan1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
samadengan1ActionPerformed(evt);
}
});
jPanel1.add(samadengan1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 260, 100, 44));
titik.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
titik.setText(".");
titik.setBorder(javax.swing.BorderFactory.createEtchedBorder());
titik.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
titikActionPerformed(evt);
}
});
jPanel1.add(titik, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 260, 45, 44));
nol.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
nol.setText("0");
nol.setBorder(javax.swing.BorderFactory.createEtchedBorder());
nol.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nolActionPerformed(evt);
}
});
jPanel1.add(nol, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 260, 44, 44));
kurangtambah1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
kurangtambah1.setText("+/-");
kurangtambah1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
kurangtambah1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kurangtambah1ActionPerformed(evt);
}
});
jPanel1.add(kurangtambah1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 260, 45, 44));
hapus1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
hapus1.setForeground(new java.awt.Color(255, 0, 0));
hapus1.setText("DEL");
hapus1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
hapus1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hapus1ActionPerformed(evt);
}
});
jPanel1.add(hapus1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 310, 150, 44));
tmbh1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
tmbh1.setText("+");
tmbh1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
tmbh1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tmbh1ActionPerformed(evt);
}
});
jPanel1.add(tmbh1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 110, 44, 44));
A1.setBackground(new java.awt.Color(204, 204, 204));
A1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
A1.setText("A");
A1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
A1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
A1ActionPerformed(evt);
}
});
jPanel1.add(A1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 110, 44, 44));
B1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
B1.setText("B");
B1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
B1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B1ActionPerformed(evt);
}
});
jPanel1.add(B1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 160, 44, 44));
C1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
C1.setText("C");
C1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
C1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
C1ActionPerformed(evt);
}
});
jPanel1.add(C1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 210, 44, 44));
E1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
E1.setText("E");
E1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
E1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
E1ActionPerformed(evt);
}
});
jPanel1.add(E1, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 160, 44, 44));
D1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
D1.setText("D");
D1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
D1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
D1ActionPerformed(evt);
}
});
jPanel1.add(D1, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 110, 44, 44));
hapus2.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
hapus2.setForeground(new java.awt.Color(255, 0, 0));
hapus2.setText("CLEAR");
hapus2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
hapus2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hapus2ActionPerformed(evt);
}
});
jPanel1.add(hapus2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 150, 44));
buttonGroup2.add(hex);
hex.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
hex.setText("HEX");
hex.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hexActionPerformed(evt);
}
});
jPanel1.add(hex, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 70, 80, -1));
buttonGroup2.add(des);
des.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
des.setText("DES");
des.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
desActionPerformed(evt);
}
});
jPanel1.add(des, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 70, -1));
buttonGroup2.add(bin);
bin.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
bin.setText("BIN");
bin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binActionPerformed(evt);
}
});
jPanel1.add(bin, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 70, 60, -1));
buttonGroup2.add(oct);
oct.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
oct.setText("OCT");
oct.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
octActionPerformed(evt);
}
});
jPanel1.add(oct, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 70, 70, -1));
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.DEFAULT_SIZE, 332, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>
private void samadengan1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka2=(Double.parseDouble(String.valueOf(area.getText())));
if(tambah1>0){
total=angka1+angka2;
area.setText(String.valueOf(total));
baru=true;
angka1=0;
angka2=0;
tambah1=0;
}
else
if(kurang1>0){
total=angka1-angka2;
area.setText(String.valueOf(total));
baru=true;
angka1=0;
angka2=0;
kurang1=0;
}
else
if(kali1>0){
total=angka1*angka2;
area.setText(String.valueOf(total));
baru=true;
angka1=0;
angka2=0;
kali1=0;
}
else
if(bagi1>0){
total=angka1/angka2;
area.setText(String.valueOf(total));
baru=true;
angka1=0;
angka2=0;
bagi1=0;
}
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null,"masuan angka","error message",
JOptionPane.ERROR_MESSAGE );
}
}
private void titikActionPerformed(java.awt.event.ActionEvent evt) {
if(desimal==0){
area.setText(area.getText()+titik.getText());
desimal=1;
}
}
private void kurangtambah1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void hapus1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
desimal=0;
if (Float.parseFloat(area.getText())>=0) {
area.setText(area.getText().substring(0,area.getText().length()-1));
if("".equals(area.getText())){
area.setText("0");
}
}
}catch(HeadlessException | NumberFormatException e){
area.setText("0");
}
}
private void satuActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+satu.getText());
// TODO add your handling code here:
}
private void duaActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+dua.getText());
// TODO add your handling code here:
}
private void tiga1ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+tiga1.getText());
// TODO add your handling code here:
}
private void empatActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+empat.getText());
// TODO add your handling code here:
}
private void limaActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+lima.getText());
// TODO add your handling code here:
}
private void enamActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+enam.getText());
// TODO add your handling code here:
}
private void tujuhActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+tujuh.getText());
// TODO add your handling code here:
}
private void delapanActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+delapan.getText());
// TODO add your handling code here:
}
private void sembilanActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+sembilan.getText());
// TODO add your handling code here:
}
private void nolActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+nol.getText());
// TODO add your handling code here:
}
private void A1ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+A1.getText());
// TODO add your handling code here:
}
private void B1ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+B1.getText());
// TODO add your handling code here:
}
private void C1ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+C1.getText());
// TODO add your handling code here:
}
private void D1ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+D1.getText());
// TODO add your handling code here:
}
private void E1ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+E1.getText());
// TODO add your handling code here:
}
private void FActionPerformed(java.awt.event.ActionEvent evt) {
area.setText(area.getText()+F.getText());
// TODO add your handling code here:
}
private void tmbh1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(area.getText())));
area.setText("");
tambah1=1;
desimal=0;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null,"masukan angka","error message",
JOptionPane.ERROR_MESSAGE);
}
}
private void kurangActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(area.getText())));
area.setText("");
kurang1=1;
desimal=0;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null,"masukan angka","error message",
JOptionPane.ERROR_MESSAGE);
}
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(area.getText())));
area.setText("");
kali1=1;
desimal=0;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null,"masukan angka","error message",
JOptionPane.ERROR_MESSAGE);
}
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(area.getText())));
area.setText("");
bagi1=1;
desimal=0;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null,"masukan angka","error message",
JOptionPane.ERROR_MESSAGE);
}
}
private void hapus2ActionPerformed(java.awt.event.ActionEvent evt) {
area.setText("0");
}
private void hexActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(true);
tiga1.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(true);
sembilan.setEnabled(true);
A1.setEnabled(true);
B1.setEnabled(true);
C1.setEnabled(true);
D1.setEnabled(true);
E1.setEnabled(true);
F.setEnabled(true);
nol.setEnabled(true);
operasi1="hex";
konversi();
}
private void octActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(true);
tiga1.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(false);
sembilan.setEnabled(false);
A1.setEnabled(false);
B1.setEnabled(false);
C1.setEnabled(false);
D1.setEnabled(false);
E1.setEnabled(false);
F.setEnabled(false);
nol.setEnabled(true);
operasi1="okt";
konversi();
}
private void desActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
dua.setEnabled(true);
tiga1.setEnabled(true);
empat.setEnabled(true);
lima.setEnabled(true);
enam.setEnabled(true);
tujuh.setEnabled(true);
delapan.setEnabled(true);
sembilan.setEnabled(true);
A1.setEnabled(false);
B1.setEnabled(false);
C1.setEnabled(false);
D1.setEnabled(false);
E1.setEnabled(false);
F.setEnabled(false);
nol.setEnabled(true);
konversi();
operasi1="des";
// TODO add your handling code here:
}
private void binActionPerformed(java.awt.event.ActionEvent evt) {
satu.setEnabled(true);
nol.setEnabled(true);
dua.setEnabled(false);
tiga1.setEnabled(false);
empat.setEnabled(false);
lima.setEnabled(false);
enam.setEnabled(false);
tujuh.setEnabled(false);
delapan.setEnabled(false);
sembilan.setEnabled(false);
A1.setEnabled(false);
B1.setEnabled(false);
C1.setEnabled(false);
D1.setEnabled(false);
E1.setEnabled(false);
F.setEnabled(false);
operasi1="bin";
konversi();
}
/**
* @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.JButton A1;
private javax.swing.JButton B1;
private javax.swing.JButton C1;
private javax.swing.JButton D1;
private javax.swing.JButton E1;
private javax.swing.JButton F;
private javax.swing.JTextField area;
private javax.swing.JButton bagi;
private javax.swing.JRadioButton bin;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JButton delapan;
private javax.swing.JRadioButton des;
private javax.swing.JButton dua;
private javax.swing.JButton empat;
private javax.swing.JButton enam;
private javax.swing.JButton hapus1;
private javax.swing.JButton hapus2;
private javax.swing.JRadioButton hex;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton kali;
private javax.swing.JButton kurang;
private javax.swing.JButton kurangtambah1;
private javax.swing.JButton lima;
private javax.swing.JButton nol;
private javax.swing.JRadioButton oct;
private javax.swing.JButton samadengan1;
private javax.swing.JButton satu;
private javax.swing.JButton sembilan;
private javax.swing.JButton tiga1;
private javax.swing.JButton titik;
private javax.swing.JButton tmbh1;
private javax.swing.JButton tujuh;
// End of variables declaration
}
======output=====
Posted by 20.46 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar