Calculator with a popup error message

javaCalc Class

This applet was constructed using the GridBagLayout and Event classes from java.awt.

To implement the calculator, first I created the layout with the text display and calculator buttons.  For the implementation of the calculations, the logic flows as follows.

First, when the applet is initialized, the textfield has the null string displayed.  As the user enters the first operand, the first digit is appended to the null string, thus displaying the entered digit.  If the first operand has more than one digit, the second digit is appended to the string containing the first digit and so on.

At this time, the first operand should be in the textfield and the user shall indicate which operation is to be performed.  Upon clicking an operation, the textfield is saved to the accumulator, the indicated operation is noted, and the textfield is cleared for the second operand.

The user then enters the second operand in the same manner as the first.  Now, then user would click the "equals" button to see the result of the desired calculation.  Upon clicking the "equals" button, the contents of the textfield is saved, the first operand is retrieved, the operation is retrieved, and the desired calculation is performed.  The result is then sent to the textfield.

To begin the next calculation, the user must press the "clear" button, else the newly entered digits will be appended to the result of the preceding calculation.

popUp Class

Detection of Interger Division,
Division by Zero,
Accumulator OverFlow
This class "Pops Up" dialog boxes to infor the user of the calculator's limited ability, or other user errors.

The popUp.class provides static methods that are called from the applet at the point in which the error occured.  For example, the method:

popUp.overFlow()

would be called as soon as the user input the 21st integer to the textfield.  These methods create the frame needed for the PopUp dialog, and passes to it the appropriate title and message to be displayed.  e.g.  Division by Zero, Overflow.

The Dialog Box has an "OK" button that closes the error dialog.  The destruction of the dialog box is handled by the actionPerformed method, coded similar to Assignment 04.

by Matthew Narrell