Membuat Kalkulator secara GUI... Hmm..
nih source code nya
karena algoritmanya dari pemikiran sndiri, dan beberapa method tidak diberi keterangan
maaf atas kekurangan yang ada
jika Anda menemukan bug pada program ini, atau Anda ingin memberi saran, harap comment pada laman ini
Thanks in advance
:D
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package calculator;
import java.awt.*;
import java.awt.event.*;
import javax.swing.* ;
import javax.swing.JOptionPane ;
import java.io.*;
/**
*
* @author Revauthore
*/
public class CalcForm extends javax.swing.JFrame{
//Variables
int tempnumb = 0;
double numb;
double snumb;
int action;
boolean dcmlsym;
double scannumb;
String bspace;
/**
* Creates new form CalcForm
*/
public CalcForm() {
//Variables
initComponents();
display.setText(Double.toString(numb));
}
public void scan(){
scannumb = Double.parseDouble(display.getText());
}
public void decimalsym(){
if ((display.getText()).contains(".")) {
dcmlsym = true;
}
else{
dcmlsym = false;
}
}
public void calc(){
snumb = Double.parseDouble(display.getText());
switch(action){
case 1 :
numb = numb / snumb;
break;
case 2 :
numb = numb * snumb;
break;
case 3 :
numb = numb - snumb;
break;
case 4 :
numb = numb + snumb;
break;
default :
break;
}
display.setText(Double.toString(numb));
action = 0;
}
/**
* 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() {
jButton4 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
display = new javax.swing.JTextField();
Butt7 = new javax.swing.JButton();
Butt8 = new javax.swing.JButton();
Butt9 = new javax.swing.JButton();
Butt4 = new javax.swing.JButton();
Butt5 = new javax.swing.JButton();
Butt6 = new javax.swing.JButton();
Butt1 = new javax.swing.JButton();
Butt2 = new javax.swing.JButton();
Butt3 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
decimal = new javax.swing.JButton();
minus = new javax.swing.JButton();
divide = new javax.swing.JButton();
equals = new javax.swing.JButton();
inverse = new javax.swing.JButton();
percent = new javax.swing.JButton();
backspace = new javax.swing.JButton();
cancelentry = new javax.swing.JButton();
clear = new javax.swing.JButton();
plusminus = new javax.swing.JButton();
multiply = new javax.swing.JButton();
plus = new javax.swing.JButton();
plusminus1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton4.setText("1");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
display.setEditable(false);
display.setFont(new java.awt.Font("Times New Roman", 3, 40)); // NOI18N
display.setToolTipText("");
display.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
display.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
displayActionPerformed(evt);
}
});
Butt7.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt7.setText("7");
Butt7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt7ActionPerformed(evt);
}
});
Butt8.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt8.setText("8");
Butt8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt8ActionPerformed(evt);
}
});
Butt9.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt9.setText("9");
Butt9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt9ActionPerformed(evt);
}
});
Butt4.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt4.setText("4");
Butt4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt4ActionPerformed(evt);
}
});
Butt5.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt5.setText("5");
Butt5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt5ActionPerformed(evt);
}
});
Butt6.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt6.setText("6");
Butt6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt6ActionPerformed(evt);
}
});
Butt1.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt1.setText("1");
Butt1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt1ActionPerformed(evt);
}
});
Butt2.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt2.setText("2");
Butt2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt2ActionPerformed(evt);
}
});
Butt3.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
Butt3.setText("3");
Butt3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Butt3ActionPerformed(evt);
}
});
jButton11.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
jButton11.setText("0");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
decimal.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
decimal.setText(".");
decimal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decimalActionPerformed(evt);
}
});
minus.setFont(new java.awt.Font("Trebuchet MS", 1, 30)); // NOI18N
minus.setText("-");
minus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minusActionPerformed(evt);
}
});
divide.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
divide.setText("/");
divide.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
divideActionPerformed(evt);
}
});
equals.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
equals.setText("=");
equals.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
equalsActionPerformed(evt);
}
});
inverse.setFont(new java.awt.Font("Trebuchet MS", 1, 18)); // NOI18N
inverse.setText("1/x");
inverse.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inverseActionPerformed(evt);
}
});
percent.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
percent.setText("%");
percent.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
percentActionPerformed(evt);
}
});
backspace.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
backspace.setText("<-");
backspace.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backspaceActionPerformed(evt);
}
});
cancelentry.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
cancelentry.setText("CE");
cancelentry.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelentryActionPerformed(evt);
}
});
clear.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
clear.setText("C");
clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearActionPerformed(evt);
}
});
plusminus.setFont(new java.awt.Font("Trebuchet MS", 1, 28)); // NOI18N
plusminus.setText("±");
plusminus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusminusActionPerformed(evt);
}
});
multiply.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
multiply.setText("x");
multiply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
multiplyActionPerformed(evt);
}
});
plus.setFont(new java.awt.Font("Trebuchet MS", 1, 25)); // NOI18N
plus.setText("+");
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});
plusminus1.setFont(new java.awt.Font("Trebuchet MS", 1, 28)); // NOI18N
plusminus1.setText("√");
plusminus1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusminus1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 18)); // NOI18N
jLabel1.setText("Revauthore~");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(display, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(backspace, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cancelentry, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(plusminus, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(plusminus1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel1))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(Butt7, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Butt8, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Butt9, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(divide, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(Butt4, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Butt5, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Butt6, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(multiply, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
.addComponent(Butt1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Butt2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(Butt3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(minus, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(plus, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(equals, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(inverse, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(percent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addGap(23, 23, 23))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(display, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(backspace, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cancelentry, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(plusminus, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(plusminus1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(inverse, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Butt7, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Butt8, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Butt9, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(divide, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Butt4, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Butt5, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Butt6, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(percent, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(multiply, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Butt1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Butt2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Butt3, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(minus, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(plus, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(equals, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
display.getAccessibleContext().setAccessibleName("");
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(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void displayActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void Butt7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("7");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"7");
}
}
private void Butt8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("8");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"8");
}
}
private void Butt9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("9");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"9");
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void Butt4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("4");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"4");
}
}
private void Butt5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("5");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"5");
}
}
private void Butt6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("6");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"6");
}
}
private void Butt1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("1");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"1");
}
}
private void Butt2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("2");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"2");
}
}
private void Butt3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
display.setText("3");
tempnumb=tempnumb+1;
}
else{
display.setText(display.getText()+"3");
}
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tempnumb==0){
}
else{
display.setText(display.getText()+"0");
}
}
private void decimalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
decimalsym();
if (tempnumb==1 || dcmlsym == false){
display.setText(display.getText()+".");
tempnumb=tempnumb+1;
}
else{
}
}
private void minusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if ((action != 0) && (tempnumb == 1)){
snumb = Double.parseDouble(display.getText());
calc();
action = 3;
tempnumb = 0;
}
else {
numb = Double.parseDouble(display.getText());
action = 3;
tempnumb = 0;
}
}
private void divideActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if ((action != 0) && (tempnumb == 1)){
snumb = Double.parseDouble(display.getText());
calc();
action = 1;
tempnumb = 0;
}
else {
numb = Double.parseDouble(display.getText());
action = 1;
tempnumb = 0;
}
}
private void equalsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if ((action != 0) && (tempnumb == 1)){
snumb = Double.parseDouble(display.getText());
calc();
action = 0;
tempnumb = 0;
}
else{
}
}
private void inverseActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
scan();
scannumb = 1 / scannumb;
display.setText(Double.toString(scannumb));
action = 0;
}
private void percentActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
scan();
if(scannumb == 0){
}
else {
scannumb = scannumb / 100;
display.setText(Double.toString(scannumb));
action = 0;
}
}
private void cancelentryActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
display.setText("0");
numb = 0;
snumb = 0;
tempnumb = 0;
action = 0;
}
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
display.setText("0");
tempnumb = 0;
}
private void plusminusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if ((Double.parseDouble(display.getText()) == 0) || tempnumb == 0){
}
else {
scan();
scannumb = scannumb * -1;
display.setText(Double.toString(scannumb));
}
}
private void backspaceActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(Double.parseDouble(display.getText())==0 ){
}
else if ((display.getText()).length()==1){
display.setText("0");
tempnumb=0;
}
else {
display.setText(display.getText().substring(0,display.getText().length()-1));
}
}
private void multiplyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if ((action != 0) && (tempnumb == 1)){
snumb = Double.parseDouble(display.getText());
calc();
action = 2;
tempnumb = 0;
}
else {
numb = Double.parseDouble(display.getText());
action = 2;
tempnumb = 0;
}
}
private void plusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if ((action != 0) && (tempnumb == 1)){
snumb = Double.parseDouble(display.getText());
calc();
action = 4;
tempnumb = 0;
}
else {
numb = Double.parseDouble(display.getText());
action = 4;
tempnumb = 0;
}
}
private void plusminus1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
scan();
if (scannumb < 0){
display.setText("Invalid because of Negative");
action = 0;
tempnumb = 0;
}
else{
scannumb = Math.sqrt(scannumb);
display.setText(Double.toString(scannumb));
action = 0;
tempnumb = 0;
}
}
/**
* @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(CalcForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CalcForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CalcForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CalcForm.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 CalcForm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Butt1;
private javax.swing.JButton Butt2;
private javax.swing.JButton Butt3;
private javax.swing.JButton Butt4;
private javax.swing.JButton Butt5;
private javax.swing.JButton Butt6;
private javax.swing.JButton Butt7;
private javax.swing.JButton Butt8;
private javax.swing.JButton Butt9;
private javax.swing.JButton backspace;
private javax.swing.JButton cancelentry;
private javax.swing.JButton clear;
private javax.swing.JButton decimal;
private javax.swing.JTextField display;
private javax.swing.JButton divide;
private javax.swing.JButton equals;
private javax.swing.JButton inverse;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JButton minus;
private javax.swing.JButton multiply;
private javax.swing.JButton percent;
private javax.swing.JButton plus;
private javax.swing.JButton plusminus;
private javax.swing.JButton plusminus1;
// End of variables declaration
}
Tertarik mencoba programnya langsung ?
Klik
disini (format .jar, pastikan terinstall JRE sebelum mengeksekusinya )
Converted to .NET
disini (format.exe, no virus guaranteed)
Selamat Mencoba :)