![]() |
Synthia
Generic and flexible data structure generator
|
A simple calculator.
The code for this window is an adaptation of the Java Codex example.
The original code on Java Codex is interesting since it contains a genuine fault that can be detected using the Monkey: clicking on − followed by = throws a NumberFormatException. This error is not intentional and corresponds to a case that the source code does not properly take into account. For the purpose of the example, this fault can be disabled from the code by calling disableNumberFormatException().
The calculator has been modified so that other exceptions can be thrown:
Definition at line 62 of file Calculator.java.

Classes | |
| class | CalculatorPanel |
| The actual panel containing the interface of the calculator. More... | |
| class | OverflowException |
| Exception that is thrown when the calculator produces an overflow. | |
| class | UnderflowException |
| Exception that is thrown when the calculator produces an underflow. | |
Public Member Functions | |
| Calculator () | |
| Creates a new calculator window. More... | |
| Calculator | hasOverflow () |
| Instructs the calculator to throw an OverflowException when producing a number over 100,000. More... | |
| Calculator | disableNumberFormatException () |
| Instructs the calculator to check the format of numbers and ignore parsing errors. More... | |
| JButton | getButton (String label) |
| Gets the button instance with given label. More... | |
| void | reset () |
| Puts the object back into its initial state. More... | |
Static Public Member Functions | |
| static void | main (String[] args) |
| A main method allowing the calculator to be run as a stand-alone application. More... | |
Static Public Attributes | |
| static final String[] | BUTTON_LABELS |
| The array of button labels. More... | |
Protected Attributes | |
| Map< String, JButton > | m_buttons |
| A map associating each button to its label. More... | |
| CalculatorPanel | m_panel |
| The calculator panel contained within the frame. More... | |
| boolean | m_checkFormat |
| A flag specifying if the calculator checks the format of numbers. More... | |
| boolean | m_hasOverflow |
| A flag specifying if the calculator produces an overflow exception. More... | |
| examples.gui.Calculator.Calculator | ( | ) |
Creates a new calculator window.
Definition at line 98 of file Calculator.java.
| Calculator examples.gui.Calculator.disableNumberFormatException | ( | ) |
Instructs the calculator to check the format of numbers and ignore parsing errors.
Definition at line 129 of file Calculator.java.
| JButton examples.gui.Calculator.getButton | ( | String | label | ) |
Gets the button instance with given label.
| label | The label |
Definition at line 141 of file Calculator.java.
| Calculator examples.gui.Calculator.hasOverflow | ( | ) |
Instructs the calculator to throw an OverflowException when producing a number over 100,000.
Definition at line 118 of file Calculator.java.
|
static |
A main method allowing the calculator to be run as a stand-alone application.
| args | Command-line arguments |
Definition at line 157 of file Calculator.java.
| void examples.gui.Calculator.reset | ( | ) |
Puts the object back into its initial state.
Implements ca.uqac.lif.synthia.Resettable.
Definition at line 147 of file Calculator.java.
|
static |
The array of button labels.
Definition at line 67 of file Calculator.java.
|
protected |
A map associating each button to its label.
Definition at line 78 of file Calculator.java.
|
protected |
A flag specifying if the calculator checks the format of numbers.
Definition at line 88 of file Calculator.java.
|
protected |
A flag specifying if the calculator produces an overflow exception.
Definition at line 93 of file Calculator.java.
|
protected |
The calculator panel contained within the frame.
Definition at line 83 of file Calculator.java.