Basic Calculator Using Java with GUI

This tutorial will show you on how to Create a Basic Calculator using Java with the four mathematical operations. The calculator is designed with GUI (Graphical User Interface).

The calculator uses a JFrame Form with jTextfield, jCombobox, jLablel, and jButton elements located in your Netbeans tool palettes.

We also use “if Statement” to identify the operation before the program calculate the two value. Please follow all the steps to complete this tutorial.

Basic Calculator in Java with GUI Steps

  1. Create/Add a new JFrameForm in your project.

2. Design the JFrameFrom the same as the image below.

3. Double-click your jButton to automatically generate the button event.

[java]private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
} [/java]

4. Insert the code below inside your button event.

[java]if (jComboBox1.getSelectedItem().equals(“Addition”)){
double result = (Double.parseDouble(jTextField1.getText()) + Double.parseDouble(jTextField2.getText()));
jTextField3.setText(Double.toString(result));
}else if (jComboBox1.getSelectedItem().equals(“Subtraction”)){
double result = (Double.parseDouble(jTextField1.getText()) – Double.parseDouble(jTextField2.getText()));
jTextField3.setText(Double.toString(result));
}else if (jComboBox1.getSelectedItem().equals(“Multiplication”)){
double result = (Double.parseDouble(jTextField1.getText()) * Double.parseDouble(jTextField2.getText()));
jTextField3.setText(Double.toString(result));
}else if (jComboBox1.getSelectedItem().equals(“Division”)){
double result = (Double.parseDouble(jTextField1.getText()) / Double.parseDouble(jTextField2.getText()));
jTextField3.setText(Double.toString(result));
}[/java]

5. Final Output

Basic Calculator using Java Output

About The Basic Calculator In Java

Project Name:Basic Calculator
Language/s Used:JAVA
Database:None
Type:Desktop Application
Developer:IT SOURCECODE
Updates:0
Basic Calculator In Java– Project Information

I hope you will find the tutorial helpful. If you have any questions or suggestions about the Basic Calculator using JavaPlease feel free to contact me on our Contact Page.

Related Tutorial you may like: Basic Calculator Using VB.Net

1 thought on “Basic Calculator Using Java with GUI”

Leave a Comment