0% found this document useful (0 votes)
24 views13 pages

Calculator

This document contains the code for a Java calculator application. It defines classes and methods for handling user input from buttons to perform basic arithmetic operations like addition, subtraction, multiplication and division. Key features include number buttons, operator buttons, an equals button, and methods for enabling/disabling buttons and performing calculations.

Uploaded by

Fadrian Çollaku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views13 pages

Calculator

This document contains the code for a Java calculator application. It defines classes and methods for handling user input from buttons to perform basic arithmetic operations like addition, subtraction, multiplication and division. Key features include number buttons, operator buttons, an equals button, and methods for enabling/disabling buttons and performing calculations.

Uploaded by

Fadrian Çollaku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package com.mycompany.calculator;

/**
*
* @author Lenovo
*/
public class calculator1 extends javax.swing.JFrame {

double num, ans;


int calculation;
public calculator1() {
initComponents();

jRadioButton1.setEnabled(false);
}

public void arithmetic_operation()


{
switch(calculation)
{
case 1 -> {
ans=num+ Double.parseDouble(jTextField1.getText());
jTextField1.setText(Double.toString(ans));
}
case 2 -> {
ans=num- Double.parseDouble(jTextField1.getText());
jTextField1.setText(Double.toString(ans));
}
case 3 -> {
ans=num *Double.parseDouble(jTextField1.getText());
jTextField1.setText(Double.toString(ans));
}
case 4 -> {
ans=num/ Double.parseDouble(jTextField1.getText());
jTextField1.setText(Double.toString(ans));
}
}
}
public void enable()
{
jTextField1.setEnabled(true);
jRadioButton1.setEnabled(true);
jRadioButton2.setEnabled(false);
jButton1.setEnabled(true);
jButton2.setEnabled(true);
jButton3.setEnabled(true);
jButton4.setEnabled(true);
jButton5.setEnabled(true);
jButton6.setEnabled(true);
jButton12.setEnabled(true);
jButton8.setEnabled(true);
jButton9.setEnabled(true);
jButton10.setEnabled(true);
jButton11.setEnabled(true);
jButton18.setEnabled(true);
jButton13.setEnabled(true);
jButton14.setEnabled(true);
jButton15.setEnabled(true);
jButton16.setEnabled(true);
jButton17.setEnabled(true);
jButton19.setEnabled(true);

public void disable()


{
jTextField1.setEnabled(false);
jRadioButton1.setEnabled(true);
jRadioButton2.setEnabled(false);
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
jButton4.setEnabled(false);
jButton5.setEnabled(false);
jButton6.setEnabled(false);
jButton12.setEnabled(false);
jButton8.setEnabled(false);
jButton9.setEnabled(false);
jButton10.setEnabled(false);
jButton11.setEnabled(false);
jButton18.setEnabled(false);
jButton13.setEnabled(false);
jButton14.setEnabled(false);
jButton15.setEnabled(false);
jButton16.setEnabled(false);
jButton17.setEnabled(false);
jButton19.setEnabled(false);

}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
jTextField1 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jButton16 = new javax.swing.JButton();
jButton17 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Calculator");
setLocation(new java.awt.Point(500, 250));
setResizable(false);
setType(java.awt.Window.Type.UTILITY);

jTextField1.setEditable(false);
jTextField1.setFont(new java.awt.Font("Segoe UI", 1, 23)); // NOI18N
jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});

buttonGroup1.add(jRadioButton1);
jRadioButton1.setFont(new java.awt.Font("Segoe UI", 1, 11)); // NOI18N
jRadioButton1.setText("ON");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});

buttonGroup1.add(jRadioButton2);
jRadioButton2.setFont(new java.awt.Font("Segoe UI", 1, 11)); // NOI18N
jRadioButton2.setText("OFF");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});

jButton1.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jButton1.setText("<--");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N


jButton2.setText("C");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton4.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton4.setText("7");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton5.setText("8");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jButton6.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton6.setText("9");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton8.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton8.setText("*");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});

jButton9.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton9.setText("4");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jButton10.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton10.setText("5");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

jButton11.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton11.setText("6");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});

jButton13.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton13.setText("1");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});

jButton14.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton14.setText("2");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton14ActionPerformed(evt);
}
});

jButton15.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton15.setText("3");
jButton15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton15ActionPerformed(evt);
}
});

jButton16.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton16.setText("0");
jButton16.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton16ActionPerformed(evt);
}
});

jButton17.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton17.setText("=");
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});

jButton19.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton19.setText(".");
jButton19.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});

jButton3.setText("+");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton18.setText("/");
jButton18.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});

jButton12.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N


jButton12.setText("-");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton16,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addComponent(jButton19,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED, 18, Short.MAX_VALUE)
.addComponent(jButton17,
javax.swing.GroupLayout.PREFERRED_SIZE, 96,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addComponent(jButton5,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton6,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addComponent(jButton12,
javax.swing.GroupLayout.PREFERRED_SIZE, 45,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton9,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Co
mponentPlacement.RELATED)
.addComponent(jButton10,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Co
mponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton11,
javax.swing.GroupLayout.PREFERRED_SIZE, 45,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton13,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Co
mponentPlacement.RELATED)
.addComponent(jButton14,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton15,
javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.LEADING, false)
.addComponent(jButton18,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jButton8,
javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))))
.addGap(31, 31, 31))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.LEADING, false)
.addComponent(jRadioButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jRadioButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 56,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addComponent(jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED)
.addComponent(jButton3,
javax.swing.GroupLayout.PREFERRED_SIZE, 44,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE, 225,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1,
javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
.addComponent(jButton2))
.addComponent(jRadioButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement
.RELATED)
.addComponent(jRadioButton2))
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton12,
javax.swing.GroupLayout.PREFERRED_SIZE, 24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(jButton10,
javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton11,
javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.BASELINE)
.addComponent(jButton14,
javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton13,
javax.swing.GroupLayout.PREFERRED_SIZE, 24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.BASELINE)
.addComponent(jButton18)
.addComponent(jButton15,
javax.swing.GroupLayout.PREFERRED_SIZE, 24,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(jButton19,
javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton17,
javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton16,
javax.swing.GroupLayout.PREFERRED_SIZE, 24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20))
);

pack();
}// </editor-fold>
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////

private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {

enable();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

int length= jTextField1.getText().length();


int number= jTextField1.getText().length() - 1;
String store;
if(length > 0)
{
StringBuilder back = new StringBuilder(jTextField1.getText());
back.deleteCharAt(number);
store=back.toString();
jTextField1.setText(store);

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


jTextField1.setText("");

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"9");
}

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"6");
}

private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"3");
}

private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {

arithmetic_operation();
jLabel1.setText("");
}

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() + "1");
}

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"2");
}

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"4");
}

private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"0");
}

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"5");
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"7");
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +"8");
}
//
private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText(jTextField1.getText() +".");
}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {

disable();
}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {

num= Double.parseDouble(jTextField1.getText());
calculation=3;
jTextField1.setText("");
jLabel1.setText(num+"*");
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

num= Double.parseDouble(jTextField1.getText());
calculation=1;
jTextField1.setText("");
jLabel1.setText(num+"+");
}

private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {

num= Double.parseDouble(jTextField1.getText());
calculation=4;
jTextField1.setText("");
jLabel1.setText(num+"/");
}

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {

num= Double.parseDouble(jTextField1.getText());
calculation=2;
jTextField1.setText("");
jLabel1.setText(num+"-");
}

/**
* @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(calculator1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(calculator1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(calculator1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(calculator1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new calculator1().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}

You might also like