Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: http://solutionzip.com/downloads/gui-calculator-java/
- Task 1. Create a GUI the following way:
- 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
- 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
- Download: http://solutionzip.com/downloads/gui-calculator-java/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement