In this tutorials will teach how to make a calculator in java step by step. How to create the calculator in java swing application in best coding practice.
String CalTotal; int num1; int num2; String option; int result;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "1"); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "2"); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "3"); } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "4"); } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "5"); } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "6"); } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "7"); } private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "8"); } private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "9"); } private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: CalTotal = txtTotal.getText(); txtTotal.setText(CalTotal + "0"); }
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { option = "+"; num1 = Integer.parseInt(txtTotal.getText()); txtTotal.setText(""); } private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: option = "-"; num1 = Integer.parseInt(txtTotal.getText()); txtTotal.setText(""); } private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: option = "*"; num1 = Integer.parseInt(txtTotal.getText()); txtTotal.setText(""); } private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: option = "/"; num1 = Integer.parseInt(txtTotal.getText()); txtTotal.setText(""); }
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) { num2 = Integer.parseInt(txtTotal.getText()); if(option.equals("+")) result = num1 + num2; if(option.equals("-")) result = num1 - num2; if(option.equals("*")) result = num1 * num2; if(option.equals("/")) result = num1 / num2; txtTotal.setText(result + ""); }
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) { txtTotal.setText(""); result = (0); num1 = (0); num2 = (0); }
Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…
Act as a Java developer to create a program that calculates the gross wage for…
Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…
In this tutorial, we will teach you how to create a simple school management system…
I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…
In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…