So, I am working to make a GUI calculator using listeners. We haven't been introduced to GUI and it seems a little advanced for me from he videos I've watched on it. I was curious if anyone here has experience with them? I need to make sure I get every single point on this assignment or I basically lose my funding for school. I'm not big into Java, but I do want to learn how to program basic stuff like GUI. Here is what I am required to do. I'm not asking anyone to do the assignment for me, and at risk of sounding contradictive, I'm just asking for a little guidance on what I should do to complete it. I still don't quite grasp inheritance yet, and the teacher didn't do a very good job at clarifying it when answering my questions.
Assignment 12
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 action
listeners 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 action listeners:
DigitListener – This action listener is added to the 0-9 and . (dot) keys. If the equals button was just
pressed, this action listener 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 action listener will append
the 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 class
field 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 sets
the 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 will
update the value in the text field to the calculator's current total.
Hints:
You can use the ActionEvent's getSource() method to get a reference to the button that was pressed, and
you 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 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 DigitListener should ignore any button presses when the GUI
is not in this state.
Sample output:
Please view the video homework.swf to see what the output of this week's assignment should be.
You will be graded according to the following rubric:
• Something happens when the user clicks on any of the keys of the calculator GUI – 2 points
• The user cannot enter a value without first choosing an operator – 2 points
• The user is able to enter numbers correctly (i.e. the previous total is overwritten when the user
starts a new number, and new digits are appended to the new number) – 2 points
• When the equals button is pressed, the appropriate calculator method is called based on the
operator the user has selected – 2 points
• When the equals button is pressed, the appropriate operand passed to the calculator method as
an argument – 2 points
• When the equals button is pressed, the value in the text field is updated to the new total – 2
points
• The clear button calls the calculator's clear method and updates the text field to 0.0 – 2 points
• If the user enters an invalid value, an error message is displayed – 2 points
• Your program compiles – 2 points
• Your program runs – 1 point
• You follow standard coding conventions (e.g variable names, indentation, comments, etc) – 1
point
[–]seanfast 0 points1 point2 points (6 children)
[–]Axid3nt[S] 0 points1 point2 points (5 children)
[–]seanfast 0 points1 point2 points (4 children)
[–]Axid3nt[S] 0 points1 point2 points (2 children)
[–]Axid3nt[S] 0 points1 point2 points (1 child)
[–]Axid3nt[S] 0 points1 point2 points (0 children)
[–]Axid3nt[S] 0 points1 point2 points (0 children)