GUI Controls Memory Calculator
This is the last homework assignment in this course, and it is meant to show you how a small butcomplete 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 actionlisteners to pass information back and forth between the calculator and the GUI. There are manypossible ways to achieve this, but the easiest is probably to develop four different action listeners:DigitListener – This action listener is added to the 0-9 and . (dot) keys. If the equals button was justpressed, this action listener will overwrite the total shown in the text field with the value of the key (itslabel) that was just pressed. If the equals button was not just pressed, this action listener will appendthe current key's label onto the end of the string shown in the text field.OperatorListener – This action listener is added to the +, -, *, and / keys. It sets the value of a classfield to the operator that the user has chosen.Clear Listener – This action listener is added to the C key. It calls the calculator's clear method and setsthe value of the text field back to 0.0.EqualsListener – This action listener 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 action listener willupdate 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 aroundwith 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 couldcreate a Super Calculator that has different views for scalar, vector, and matrix calculations. Whateveryou come up with, I suggest you clean it up and document it. Potential employers always lookfavorably 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, andyou can use JButton's getText() method to find out the label of that button.When the EqualsListener is converting the text shown in the text field into a double value in order topass 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, andabort 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 whenthe equals button has been pushed. The DigitListener should ignore any button presses when the GUIis not in this state.
You'll get a 13.3KB .RAR file.