Membuat Kalkulator
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Algo_2;
import java.awt.event.KeyEvent;
import javax.print.attribute.standard.OutputDeviceAssigned;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.*;
import javax.swing.*; // mengimport paket swing
import java.awt.*;
import java.text.DecimalFormat;
/**
*
* @author Toshiba
*/
public class kalkulatorku extends javax.swing.JFrame {
double operator, hasil, bil1;
String bil;
int komas=0,pusing=0;
/**
* Creates new form kalkulatorku
*/
public kalkulatorku() {
initComponents();
setTitle("K A L K U L A T O R K U by : Bagus Dermawan");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
dec.setSelected(true);
no1.setEnabled(true);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
no8.setEnabled(true);
no9.setEnabled(true);
no0.setEnabled(true);
koma.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
}
//opereasi KONVERSI BILANGAN
String operasi="des",operasi1="";
public void biokhex(){
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 del (){
output.setText("");
}
/**
* 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() {
buttonGroup2 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
output = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
no0 = new javax.swing.JButton();
no8 = new javax.swing.JButton();
no9 = new javax.swing.JButton();
no6 = new javax.swing.JButton();
no5 = new javax.swing.JButton();
no2 = new javax.swing.JButton();
no3 = new javax.swing.JButton();
no1 = new javax.swing.JButton();
no4 = new javax.swing.JButton();
no7 = new javax.swing.JButton();
koma = new javax.swing.JButton();
clear = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
tambah = new javax.swing.JButton();
kurang = new javax.swing.JButton();
kali = new javax.swing.JButton();
bagi = new javax.swing.JButton();
mod = new javax.swing.JButton();
samadengan = new javax.swing.JButton();
plusmin = new javax.swing.JButton();
persen = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
bin = new javax.swing.JRadioButton();
dec = new javax.swing.JRadioButton();
oct = new javax.swing.JRadioButton();
hex = new javax.swing.JRadioButton();
jPanel6 = new javax.swing.JPanel();
A = new javax.swing.JButton();
B = new javax.swing.JButton();
C = new javax.swing.JButton();
D = new javax.swing.JButton();
E = new javax.swing.JButton();
F = new javax.swing.JButton();
hapus = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jMenuBar2 = new javax.swing.JMenuBar();
jMenu3 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(51, 0, 51));
output.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
output.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
output.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
outputKeyPressed(evt);
}
});
jPanel2.setBackground(new java.awt.Color(255, 255, 255));
no0.setText("0");
no0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no0ActionPerformed(evt);
}
});
no8.setText("8");
no8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no8ActionPerformed(evt);
}
});
no9.setText("9");
no9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no9ActionPerformed(evt);
}
});
no6.setText("6");
no6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no6ActionPerformed(evt);
}
});
no5.setText("5");
no5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no5ActionPerformed(evt);
}
});
no2.setText("2");
no2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no2ActionPerformed(evt);
}
});
no3.setText("3");
no3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no3ActionPerformed(evt);
}
});
no1.setText("1");
no1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no1ActionPerformed(evt);
}
});
no1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
no1KeyPressed(evt);
}
});
no4.setText("4");
no4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no4ActionPerformed(evt);
}
});
no7.setText("7");
no7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no7ActionPerformed(evt);
}
});
koma.setText(",");
koma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
komaActionPerformed(evt);
}
});
clear.setText("CE");
clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearActionPerformed(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)
.addComponent(no1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clear, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(no5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
.addComponent(no0, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(10, 10, 10)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(no9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
.addComponent(no6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(koma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(no1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(no4, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no6, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no5, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(no7, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no8, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no9, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(no0, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(koma, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
tambah.setText("+");
tambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tambahActionPerformed(evt);
}
});
kurang.setText("-");
kurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kurangActionPerformed(evt);
}
});
kali.setText("x");
kali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kaliActionPerformed(evt);
}
});
bagi.setText("/");
bagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bagiActionPerformed(evt);
}
});
mod.setText("Mod");
mod.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modActionPerformed(evt);
}
});
samadengan.setText("=");
samadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
samadenganActionPerformed(evt);
}
});
plusmin.setText("+/-");
plusmin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusminActionPerformed(evt);
}
});
persen.setText("%");
persen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
persenActionPerformed(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.TRAILING, false)
.addComponent(plusmin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tambah, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(mod, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(kali, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(bagi, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(samadengan, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(persen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
.addComponent(kurang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(13, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tambah, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(kurang, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(kali, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bagi, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(mod, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
.addComponent(persen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(samadengan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(plusmin, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
bin.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup2.add(bin);
bin.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
bin.setText("Binner");
bin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binActionPerformed(evt);
}
});
dec.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup2.add(dec);
dec.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
dec.setText("Decimal");
dec.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decActionPerformed(evt);
}
});
oct.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup2.add(oct);
oct.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
oct.setText("Octal");
oct.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
octActionPerformed(evt);
}
});
hex.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup2.add(hex);
hex.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
hex.setText("Hexadecimal");
hex.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hexActionPerformed(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()
.addGap(8, 8, 8)
.addComponent(bin)
.addGap(64, 64, 64)
.addComponent(dec)
.addGap(63, 63, 63)
.addComponent(oct)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(hex)
.addGap(16, 16, 16))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(9, 9, 9)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hex)
.addComponent(oct)
.addComponent(dec)
.addComponent(bin))
.addContainerGap(10, Short.MAX_VALUE))
);
jPanel6.setBackground(new java.awt.Color(255, 255, 255));
A.setText("A");
A.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AActionPerformed(evt);
}
});
B.setText("B");
B.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BActionPerformed(evt);
}
});
C.setText("C");
C.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CActionPerformed(evt);
}
});
D.setText("D");
D.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DActionPerformed(evt);
}
});
E.setText("E");
E.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EActionPerformed(evt);
}
});
F.setText("F");
F.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FActionPerformed(evt);
}
});
hapus.setText("Backspace");
hapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hapusActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(A, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(B, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(C, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(D, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(E, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(F, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(hapus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel6Layout.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, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(D, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(C, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(E, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(F, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(hapus, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jLabel1.setFont(new java.awt.Font("Sylfaen", 1, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Kalkulator");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(198, 198, 198)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(output)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(26, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(output, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, 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)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(32, Short.MAX_VALUE))
);
jMenu3.setText("File");
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Clear All");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem2);
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem3.setText("Exit");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem3);
jMenuBar2.add(jMenu3);
jMenu4.setText("About");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("About Me");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu4.add(jMenuItem1);
jMenuBar2.add(jMenu4);
setJMenuBar(jMenuBar2);
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()
.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))
);
pack();
}// </editor-fold>
private void modActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 5;
bil1 = Double.parseDouble(output.getText());
output.setText("");
}
private void no1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+1);
}
private void no2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+2);
}
private void no3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+3);
}
private void no4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+4);
}
private void no5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+5);
}
private void no6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+6);
}
private void no7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+7);
}
private void no8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+8);
}
private void no9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+9);
}
private void no0ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+0);
}
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText("");
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+".");
}
private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(operator==1){
hasil = bil1+Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==2){
hasil = bil1-Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==3){
hasil = bil1*Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==4){
hasil = bil1/Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==5){
hasil = bil1%Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==6){
if(hasil<0){
output.setText("Syntax Error");
}else{
hasil = Math.pow(bil1, Double.parseDouble(output.getText()));
output.setText(String.valueOf(hasil));
}
}
}
private void tambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 1;
bil1 = Double.parseDouble(output.getText());
output.setText("");
}
private void kurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 2;
bil1 = Double.parseDouble(output.getText());
output.setText("");
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 3;
bil1 = Double.parseDouble(output.getText());
output.setText("");
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 4;
bil1 = Double.parseDouble(output.getText());
output.setText("");
}
private void hapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (Float.parseFloat(output.getText())>=0) {
komas=0;
pusing=0;
output.setText(output.getText().substring(0,output.getText().length()-1));
//output.setText(output.getText());
if ("".equals(output.getText())) {
output.setText("");
}
}
}
private void plusminActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
hasil = Double.parseDouble(output.getText())*-1;
output.setText(String.valueOf(hasil));
}
private void binActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no2.setEnabled(false);
no3.setEnabled(false);
no4.setEnabled(false);
no5.setEnabled(false);
no6.setEnabled(false);
no7.setEnabled(false);
no8.setEnabled(false);
no9.setEnabled(false);
koma.setEnabled(false);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
operasi1="bin";
biokhex();
}
private void octActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no8.setEnabled(false);
no9.setEnabled(false);
koma.setEnabled(false);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
operasi1="okt";
biokhex();
}
private void decActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no1.setEnabled(true);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
no8.setEnabled(true);
no9.setEnabled(true);
no0.setEnabled(true);
koma.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
operasi1="des";
biokhex();
}
private void hexActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no1.setEnabled(true);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
no8.setEnabled(true);
no9.setEnabled(true);
no0.setEnabled(true);
koma.setEnabled(true);
A.setEnabled(true);
B.setEnabled(true);
C.setEnabled(true);
D.setEnabled(true);
E.setEnabled(true);
F.setEnabled(true);
operasi1="hex";
biokhex();
}
private void AActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String f = "a";
output.setText(output.getText()+f);
}
private void BActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String f = "b";
output.setText(output.getText()+f);
}
private void CActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String f = "c";
output.setText(output.getText()+f);
}
private void DActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String f = "d";
output.setText(output.getText()+f);
}
private void EActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String f = "e";
output.setText(output.getText()+f);
}
private void FActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String f = "f";
output.setText(output.getText()+f);
}
private void no1KeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void outputKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
samadengan.doClick();}
}
private void persenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
hasil = Double.parseDouble(output.getText())/100;
output.setText(String.valueOf(hasil));
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
AboutMe about = new AboutMe();
about.setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
del();
}
/**
* @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(kalkulatorku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalkulatorku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalkulatorku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalkulatorku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new kalkulatorku().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 bagi;
private javax.swing.JRadioButton bin;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JButton clear;
private javax.swing.JRadioButton dec;
private javax.swing.JButton hapus;
private javax.swing.JRadioButton hex;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel6;
private javax.swing.JButton kali;
private javax.swing.JButton koma;
private javax.swing.JButton kurang;
private javax.swing.JButton mod;
private javax.swing.JButton no0;
private javax.swing.JButton no1;
private javax.swing.JButton no2;
private javax.swing.JButton no3;
private javax.swing.JButton no4;
private javax.swing.JButton no5;
private javax.swing.JButton no6;
private javax.swing.JButton no7;
private javax.swing.JButton no8;
private javax.swing.JButton no9;
private javax.swing.JRadioButton oct;
private javax.swing.JTextField output;
private javax.swing.JButton persen;
private javax.swing.JButton plusmin;
private javax.swing.JButton samadengan;
private javax.swing.JButton tambah;
// End of variables declaration
}
//Outputan
Atau Biar Gak Ribet Download Filenya disini
Nama : Bagus Dermawan
Nim : 2012420050
Posted by 11.31 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar