The document provides code to add functionality to buttons for a basic calculator application. Code is provided to clear text fields with one button, and perform addition, subtraction, multiplication, and division calculations by parsing text fields as floats and setting the result to the third text field for each respective button.
1 of 12
Downloaded 10 times
More Related Content
Net beansprojects
4. Coding
Double click the exit button and type the
following code as it is: System.exit(0);
Then double click the clear button and type
the following code in it:
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
6. Coding
Double click the add button and type the
following coding in it:
Float num1, num2, result;
num1= Float.parseFloat(jTextField1.getText());
num2= Float.parseFloat(jTextField2.getText());
result= num1 + num2;
jTextField3.setText(String.valueOf(result));
7. Double click the subtract button and type the
following coding in it:
Float num1, num2, result;
num1= Float.parseFloat(jTextField1.getText());
num2= Float.parseFloat(jTextField2.getText());
result= num1 - num2;
jTextField3.setText(String.valueOf(result));
8. Double click the multiply button and type the
following coding in it:
Float num1, num2, result;
num1= Float.parseFloat(jTextField1.getText());
num2= Float.parseFloat(jTextField2.getText());
result= num1 * num2;
jTextField3.setText(String.valueOf(result));
9. Double click the divide button and type the
following coding in it:
Float num1, num2, result;
num1= Float.parseFloat(jTextField1.getText());
num2= Float.parseFloat(jTextField2.getText());
result= num1 / num2;
jTextField3.setText(String.valueOf(result));