* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alpro2;
import java.awt.HeadlessException;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/**
*
* @author -
*/
public class KalkulatorTugas extends javax.swing.JFrame {
boolean kom, anyar, clear;
public KalkulatorTugas() {
initComponents();
output.setHorizontalAlignment(JTextField.RIGHT);
setTitle("KALKULATOR SEDERHANA");
decimal.setSelected(true);
semb();
}
int plusklik;
int minklik;
int kaliklik;
int bagiklik;
int modklik;
int decklik;
int binklik;
int octklik;
int hexklik;
double angka1;
double angka2;
double total;
String operasi="des",operasi1="";
public void konversi(){
try{
String mon = output.getText();
if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("des")){
output.setText(""+Integer.parseInt(mon,2));
operasi="des";
}
else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,2);
output.setText(""+Integer.toOctalString(a));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,2);
output.setText(""+Integer.toHexString(a));
operasi="hex";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,8);
output.setText(""+a);
operasi="des";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,8);
output.setText(""+Integer.toBinaryString(a));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("okt")&& operasi1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,8);
output.setText(""+Integer.toHexString(a));
operasi="hex";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,16);
output.setText(""+a);
operasi="des";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,16);
output.setText(""+Integer.toBinaryString(a));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("hex")&& operasi1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,16);
output.setText(""+Integer.toOctalString(a));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("bin")){
output.setText(""+Integer.toBinaryString(Integer.parseInt(mon)));
operasi="bin";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("okt")){
output.setText(""+Integer.toOctalString(Integer.parseInt(mon)));
operasi="okt";
}
else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("hex")){
output.setText(""+Integer.toHexString(Integer.parseInt(mon)));
operasi="hex";
}
}catch(NumberFormatException ab){
output.setText("error");
}
}
void semb(){
if (decimal.isSelected()){
a.setEnabled(true);
b.setEnabled(true);
c.setEnabled(true);
d.setEnabled(true);
e.setEnabled(true);
f.setEnabled(true);
g.setEnabled(true);
h.setEnabled(true);
i.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
nol.setEnabled(true);
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
output = new javax.swing.JTextField();
hexa = new javax.swing.JRadioButton();
biner = new javax.swing.JRadioButton();
octal = new javax.swing.JRadioButton();
decimal = new javax.swing.JRadioButton();
a = new javax.swing.JButton();
b = new javax.swing.JButton();
c = new javax.swing.JButton();
f = new javax.swing.JButton();
e = new javax.swing.JButton();
d = new javax.swing.JButton();
g = new javax.swing.JButton();
h = new javax.swing.JButton();
i = new javax.swing.JButton();
hasil = new javax.swing.JButton();
tanda = new javax.swing.JButton();
plus = new javax.swing.JButton();
minus = new javax.swing.JButton();
kali = new javax.swing.JButton();
mod = new javax.swing.JButton();
nol = new javax.swing.JButton();
koma = new javax.swing.JButton();
reset = new javax.swing.JButton();
A = new javax.swing.JButton();
C = new javax.swing.JButton();
B = new javax.swing.JButton();
D = new javax.swing.JButton();
E = new javax.swing.JButton();
F = new javax.swing.JButton();
delete = new javax.swing.JButton();
bagi = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(0, 0, 153));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
output.setEditable(false);
output.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
output.setBorder(javax.swing.BorderFactory.createEtchedBorder());
output.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
outputActionPerformed(evt);
}
});
jPanel1.add(output, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 290, 29));
buttonGroup1.add(hexa);
hexa.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
hexa.setText("HEX");
hexa.setBorder(null);
hexa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hexaActionPerformed(evt);
}
});
jPanel1.add(hexa, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 50, 50, 20));
buttonGroup1.add(biner);
biner.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
biner.setText("BIN");
biner.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binerActionPerformed(evt);
}
});
jPanel1.add(biner, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 50, -1, 20));
buttonGroup1.add(octal);
octal.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
octal.setText("OCT");
octal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
octalActionPerformed(evt);
}
});
jPanel1.add(octal, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 50, -1, 20));
buttonGroup1.add(decimal);
decimal.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
decimal.setText("DEC");
decimal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decimalActionPerformed(evt);
}
});
jPanel1.add(decimal, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, -1, 20));
a.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
a.setText("1");
a.setBorder(javax.swing.BorderFactory.createEtchedBorder());
a.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aActionPerformed(evt);
}
});
jPanel1.add(a, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 80, 50, 40));
b.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
b.setText("2");
b.setBorder(javax.swing.BorderFactory.createEtchedBorder());
b.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bActionPerformed(evt);
}
});
jPanel1.add(b, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 80, 51, 40));
c.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
c.setText("3");
c.setBorder(javax.swing.BorderFactory.createEtchedBorder());
c.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cActionPerformed(evt);
}
});
jPanel1.add(c, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 80, 51, 40));
f.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
f.setText("6");
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(130, 130, 51, 40));
e.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
e.setText("5");
e.setBorder(javax.swing.BorderFactory.createEtchedBorder());
e.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
eActionPerformed(evt);
}
});
jPanel1.add(e, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 130, 51, 40));
d.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
d.setText("4");
d.setBorder(javax.swing.BorderFactory.createEtchedBorder());
d.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dActionPerformed(evt);
}
});
jPanel1.add(d, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 52, 40));
g.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
g.setText("7");
g.setBorder(javax.swing.BorderFactory.createEtchedBorder());
g.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gActionPerformed(evt);
}
});
jPanel1.add(g, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, 52, 40));
h.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
h.setText("8");
h.setBorder(javax.swing.BorderFactory.createEtchedBorder());
h.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hActionPerformed(evt);
}
});
jPanel1.add(h, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 180, 51, 40));
i.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
i.setText("9");
i.setBorder(javax.swing.BorderFactory.createEtchedBorder());
i.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
iActionPerformed(evt);
}
});
jPanel1.add(i, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 180, 51, 40));
hasil.setFont(new java.awt.Font("Arial Black", 1, 24)); // NOI18N
hasil.setText("=");
hasil.setBorder(javax.swing.BorderFactory.createEtchedBorder());
hasil.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hasilActionPerformed(evt);
}
});
jPanel1.add(hasil, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 280, 50, 30));
tanda.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
tanda.setText("-");
tanda.setBorder(javax.swing.BorderFactory.createEtchedBorder());
tanda.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tandaActionPerformed(evt);
}
});
jPanel1.add(tanda, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, 50, 40));
plus.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
plus.setText("+");
plus.setBorder(javax.swing.BorderFactory.createEtchedBorder());
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});
jPanel1.add(plus, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 80, 50, 30));
minus.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
minus.setText("-");
minus.setBorder(javax.swing.BorderFactory.createEtchedBorder());
minus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minusActionPerformed(evt);
}
});
jPanel1.add(minus, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 120, 50, 30));
kali.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
kali.setText("x");
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(250, 160, 50, 30));
mod.setFont(new java.awt.Font("Arial Black", 1, 8)); // NOI18N
mod.setText("mod");
mod.setBorder(javax.swing.BorderFactory.createEtchedBorder());
mod.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modActionPerformed(evt);
}
});
jPanel1.add(mod, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 240, 50, 30));
nol.setFont(new java.awt.Font("Arial Black", 1, 14)); // 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(70, 230, 51, 40));
koma.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
koma.setText(".");
koma.setBorder(javax.swing.BorderFactory.createEtchedBorder());
koma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
komaActionPerformed(evt);
}
});
jPanel1.add(koma, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 230, 50, 40));
reset.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
reset.setText("CLEAR");
reset.setBorder(javax.swing.BorderFactory.createEtchedBorder());
reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetActionPerformed(evt);
}
});
jPanel1.add(reset, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 280, 80, 30));
A.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
A.setText("A");
A.setBorder(javax.swing.BorderFactory.createEtchedBorder());
A.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AActionPerformed(evt);
}
});
jPanel1.add(A, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 80, 50, 30));
C.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
C.setText("C");
C.setBorder(javax.swing.BorderFactory.createEtchedBorder());
C.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CActionPerformed(evt);
}
});
jPanel1.add(C, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 160, 50, 30));
B.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
B.setText("B");
B.setBorder(javax.swing.BorderFactory.createEtchedBorder());
B.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BActionPerformed(evt);
}
});
jPanel1.add(B, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 120, 50, 30));
D.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
D.setText("D");
D.setBorder(javax.swing.BorderFactory.createEtchedBorder());
D.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
D.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DActionPerformed(evt);
}
});
jPanel1.add(D, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 200, 50, 30));
E.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
E.setText("E");
E.setBorder(javax.swing.BorderFactory.createEtchedBorder());
E.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EActionPerformed(evt);
}
});
jPanel1.add(E, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 240, 50, 30));
F.setFont(new java.awt.Font("Arial Black", 1, 14)); // 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(190, 280, 50, 30));
delete.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
delete.setText("DEL");
delete.setBorder(javax.swing.BorderFactory.createEtchedBorder());
delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteActionPerformed(evt);
}
});
jPanel1.add(delete, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 280, 80, 30));
bagi.setFont(new java.awt.Font("Arial Black", 1, 14)); // 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(250, 200, 50, 30));
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.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void hexaActionPerformed(java.awt.event.ActionEvent evt) {
a.setEnabled(true);
b.setEnabled(true);
c.setEnabled(true);
d.setEnabled(true);
e.setEnabled(true);
f.setEnabled(true);
g.setEnabled(true);
h.setEnabled(true);
i.setEnabled(true);
A.setEnabled(true);
B.setEnabled(true);
C.setEnabled(true);
D.setEnabled(true);
E.setEnabled(true);
F.setEnabled(true);
nol.setEnabled(true);
operasi1="hex";
konversi();
}
private void outputActionPerformed(java.awt.event.ActionEvent evt) {
}
private void aActionPerformed(java.awt.event.ActionEvent evt) {
if ("0".equals(output.getText())) {
output.setText("");
}
if(anyar){
output.setText("1");
anyar=false;
}
else {
output.setText(output.getText() + "1");
}
}
private void octalActionPerformed(java.awt.event.ActionEvent evt) {
a.setEnabled(true);
b.setEnabled(true);
c.setEnabled(true);
d.setEnabled(true);
e.setEnabled(true);
f.setEnabled(true);
g.setEnabled(true);
h.setEnabled(false);
i.setEnabled(false);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
nol.setEnabled(true);
operasi1="okt";
konversi();
}
private void bActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("2");
anyar=false;
}else{
output.setText(output.getText()+"2");
}
}
private void cActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("3");
anyar=false;
}else
output.setText(output.getText()+"3"); // TODO add your handling code here:
}
private void fActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("6");
anyar=false;
}else
output.setText(output.getText()+"6"); // TODO add your handling code here:
}
private void eActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("5");
anyar=false;
}else
output.setText(output.getText()+"5");// TODO add your handling code here:
}
private void dActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("4");
anyar=false;
}else
output.setText(output.getText()+"4"); // TODO add your handling code here:
}
private void gActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("7");
anyar=false;
}else
output.setText(output.getText()+"7"); // TODO add your handling code here:
}
private void hActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("8");
anyar=false;
}else
output.setText(output.getText()+"8"); // TODO add your handling code here:
}
private void iActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("9");
anyar=false;
}else
output.setText(output.getText()+"9"); // TODO add your handling code here:
}
private void hasilActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka2=(Double.parseDouble(String.valueOf(output.getText())));
if(plusklik>0){
total=angka1+angka2;
output.setText(String.valueOf(total));
anyar=true;
angka1=0;
angka2=0;
plusklik=0;
}
else
if(minklik>0){
total=angka1-angka2;
output.setText(String.valueOf(total));
anyar=true;
angka1=0;
angka2=0;
minklik=0;
}
else
if(kaliklik>0){
total=angka1*angka2;
output.setText(String.valueOf(total));
anyar=true;
angka1=0;
angka2=0;
kaliklik=0;
}
else
if(bagiklik>0){
total=angka1/angka2;
output.setText(String.valueOf(total));
anyar=true;
angka1=0;
angka2=0;
bagiklik=0;
}
else
if(modklik>0){
total=angka1%angka2;
output.setText(String.valueOf(total));
anyar=true;
angka1=0;
angka2=0;
modklik=0;
}
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null, "Masukkan Angka","Error Message", JOptionPane.ERROR_MESSAGE);
}
}
private void tandaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void plusActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(output.getText())));
plusklik=1;
decklik=0;
anyar=true;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null, "Masukkan Angka","Error Message", JOptionPane.ERROR_MESSAGE);
}
}
private void nolActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("0");
anyar=false;
}else
output.setText(output.getText()+"0");// TODO add your handling code here:
}
private void minusActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(output.getText())));
minklik=1;
decklik=0;
anyar=true;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null, "Masukkan Angka","Error Message", JOptionPane.ERROR_MESSAGE);
}
}
private void decimalActionPerformed(java.awt.event.ActionEvent evt) {
a.setEnabled(true);
b.setEnabled(true);
c.setEnabled(true);
d.setEnabled(true);
e.setEnabled(true);
f.setEnabled(true);
g.setEnabled(true);
h.setEnabled(true);
i.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
nol.setEnabled(true);
operasi1="des";
konversi();
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
if(decklik==0){
output.setText(output.getText()+koma.getText());
decklik=1;
}
}
private void binerActionPerformed(java.awt.event.ActionEvent evt) {
a.setEnabled(true);
nol.setEnabled(true);
b.setEnabled(false);
c.setEnabled(false);
d.setEnabled(false);
e.setEnabled(false);
f.setEnabled(false);
g.setEnabled(false);
h.setEnabled(false);
i.setEnabled(false);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
operasi1="bin";
konversi();
}
private void resetActionPerformed(java.awt.event.ActionEvent evt) {
output.setText("0");
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(output.getText())));
kaliklik=1;
decklik=0;
anyar=true;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null, "Masukkan Angka","Error Message", JOptionPane.ERROR_MESSAGE);
} // TODO add your handling code here:
}
private void modActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(output.getText())));
modklik=1;
decklik=0;
anyar=true;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null, "Masukkan Angka","Error Message", JOptionPane.ERROR_MESSAGE);
} // TODO add your handling code here:
}
private void BActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("b");
anyar=false;
}else
output.setText(output.getText()+"b"); // TODO add your handling code here:
}
private void CActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("c");
anyar=false;
}else
output.setText(output.getText()+"c"); // TODO add your handling code here:
}
private void DActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("d");
anyar=false;
}else
output.setText(output.getText()+"d"); // TODO add your handling code here:
}
private void AActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("a");
anyar=false;
}else
output.setText(output.getText()+"a"); // TODO add your handling code here:
}
private void deleteActionPerformed(java.awt.event.ActionEvent evt) {
try {
decklik=0;
if (Float.parseFloat(output.getText())>=0) {
output.setText(output.getText().substring(0,output.getText().length()-1));
if("".equals(output.getText())){
output.setText("0");
}
}
}catch(HeadlessException | NumberFormatException e){
output.setText("0");
}
}
private void EActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("e");
anyar=false;
}else
output.setText(output.getText()+"e"); // TODO add your handling code here:
}
private void FActionPerformed(java.awt.event.ActionEvent evt) {
if("0".equals(output.getText())){
output.setText("");
}
if(anyar){
output.setText("f");
anyar=false;
}else
output.setText(output.getText()+"f"); // TODO add your handling code here:
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
try{
angka1=(Double.parseDouble(String.valueOf(output.getText())));
bagiklik=1;
decklik=0;
anyar=true;
}catch(HeadlessException | NumberFormatException e){
JOptionPane.showMessageDialog(null, "Masukkan Angka","Error Message", JOptionPane.ERROR_MESSAGE);
}
// TODO add your handling code here:
// TODO add your handling code here:
}
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(KalkulatorTugas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(KalkulatorTugas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(KalkulatorTugas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(KalkulatorTugas.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 KalkulatorTugas().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 D;
private javax.swing.JButton E;
private javax.swing.JButton F;
private javax.swing.JButton a;
private javax.swing.JButton b;
private javax.swing.JButton bagi;
private javax.swing.JRadioButton biner;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton c;
private javax.swing.JButton d;
private javax.swing.JRadioButton decimal;
private javax.swing.JButton delete;
private javax.swing.JButton e;
private javax.swing.JButton f;
private javax.swing.JButton g;
private javax.swing.JButton h;
private javax.swing.JButton hasil;
private javax.swing.JRadioButton hexa;
private javax.swing.JButton i;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton kali;
private javax.swing.JButton koma;
private javax.swing.JButton minus;
private javax.swing.JButton mod;
private javax.swing.JButton nol;
private javax.swing.JRadioButton octal;
private javax.swing.JTextField output;
private javax.swing.JButton plus;
private javax.swing.JButton reset;
private javax.swing.JButton tanda;
// End of variables declaration
}
OUTPUT
Posted by 00.26 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar