Lab7 GUI CALCULATOR

Task 1. Create a GUI the following way:

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

You need 3 Text Fileds, placed one under another. Use layouts of your choice, recommendation: use a JPanel for each.

Add a label to each field (on the same panel, with FLowLayout)

Field 1 – First  Number

Field 2 – Second Number

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Field 3 – Result

Make Result field non-editable

On a separate panel under the Text fields create 5 buttons, “+”, “-“, “*”,“/”, and Reset

(or Add, Subtract, Multiply, and Divide (your choice))

Be assures that GUI looks as you want, snip and submit.

For the time being actionPerformed() is an empty method. (10 points)

 

Task2.  Write actionPerformed() method which reads Fields 1 and 2, calculates the result, and places it into Field 3. Create helper methods

 1.to read an integer from a JTextField, passed as a parameter throwing a NumberFormatException, could be a different, you find it by testing different inputs including  an empty string

Result has to be double to handle division.

2 to perform division, throwing DivideByZeroException,  you will need a class DivisionByZeroException for this.

Catch exceptions in the actionPerformed method. Do not exit the program,  but clear all the Fields instead and send JOptionPane ERROR_MESSAGE with description of the actual error. 

if you push Reset Button, clear the fields.

More interesting scenario: at start and on Reset make Result field invisible; make it visible after pushing operation Button to show the result

 (20 points)

Still stressed with your coursework?
Get quality coursework help from an expert!