- Simple Calculator built with Eclipse window builder
- After optimizing the app, updated image is as following:
- Made some UI changes, result as following:
-
Java Swing
application for a mini calculator. It creates aGUI window
with various buttons and a text field to perform basic arithmetic calculations. -
Here's a breakdown of the code:
- The class
Optimization
extendsJFrame
to create the main frame for the calculator. - The constructor sets up the frame by setting its size, title, and default close operation.
- The
contentPane
panel is created and set as the content pane for the frame. - Various Swing components such as buttons, labels, and text fields are created and added to the content pane.
- Action listeners are added to the buttons to perform specific operations when clicked.
- The
btnPlus
,btnMinus
,btnMultiply
,btnDivide
, andbtnSquare_1
buttons set theoperation
variable to the respective operation symbol (+
,-
,*
,/
,<html>x<sup>y</sup></html>
). - The
btnEqual
button calculates the result based on the selected operation and displays it in the text field (tfNumber
) and a label (lbCalculation
). - Other buttons (
btnSqrt
,btnSquare
,btnClear
,btnOne
,btnTwo
, ...,btnNine
,btnZero
) handle specific actions such as square root, square, clearing the text field, and entering numeric values. - The
Optimization
class represents the main window of the calculator application.
- The class
-
To run this code, we need to have the necessary dependencies for Java Swing and compile and execute the code using a Java development environment.