Create an instance of memorycalc in the calcgui and write


GUI Controls Memory Calculator

This is the last homework assignment in this course, and it is meant to show you how a small but complete GUI application is structured. We will make our GUI actually control our memory calculator.

To do this, you will need to create an instance of MemoryCalc in the CalcGUI and write event Handlers to pass information back and forth between the calculator and the GUI. There are many possible ways to achieve this, but the easiest is probably to develop four different event Handlers:

DigitHandler - This event Handler is added to the 0-9 and . (dot) keys. If the equals button was just pressed, this event Handler will overwrite the total shown in the text field with the value of the key (its label) that was just pressed. If the equals button was not just pressed, this event Handler will append the current key's label onto the end of the string shown in the text field.

OperatorHandler - This event Handler is added to the +, -, *, and / keys. It sets the value of a class field to the operator that the user has chosen.

ClearHandler - This event Handler is added to the C key. It calls the calculator's clear method and sets the value of the text field back to 0.0.

EqualsHandler - This event Handler is added to the = key. It reads the current value from the text field, converts it to a double, and calls the appropriate calculator method based on the current operator, passing in the double value. The calculator will compute the answer, and then this event Handler will update the value in the text field to the calculator's current total.

That is all that required for the homework assignment, however I also encourage you to play around with the different types of calculators we have written in this course, perhaps after this course ends. For instance, you could add functionality for geometric operations like sine and cosine. Or you could create a Super Calculator that has different views for scalar, vector, and matrix calculations. Whatever you come up with, I suggest you clean it up and document it. Potential employers always look favorably on being able to review code you have written and ask you questions about it.

Hints:

You can use the ActionEvent's getSource() method to get a reference to the button that was pressed, and you can use Button's getText() method to find out the label of that button.

When the EqualsHandler is converting the text shown in the text field into a double value in order to pass it to the calculator, be careful to handle the case where the text field contains an invalid value, such as 6..72. In this case you should catch the exception, display an error message to the user, and abort the call to the calculator (just restore the current total to the text field).

The user should only be able to enter numbers between when an operator has been selected and when the equals button has been pushed. The DigitHandler should ignore any button presses when the GUI is not in this state.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create an instance of memorycalc in the calcgui and write
Reference No:- TGS02374526

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)