 |
Synthia
Generic and flexible data structure generator
|
Go to the documentation of this file.
21 import java.awt.BorderLayout;
22 import java.awt.Container;
23 import java.awt.GridLayout;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.HashMap;
29 import javax.swing.JButton;
30 import javax.swing.JFrame;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
68 "4",
"5",
"6",
"\u00d7",
"1",
"2",
"3",
"\u2212",
"0",
".",
"=",
"+"};
73 private static final long serialVersionUID = 1L;
101 m_buttons =
new HashMap<String,JButton>();
102 setTitle(
"Calculator");
104 setLocationRelativeTo(
null);
105 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
106 Container contentPane = getContentPane();
157 public static void main(String[] args)
171 private static final long serialVersionUID = 1L;
173 private JTextField display =
new JTextField(
"0");
174 private double result = 0;
175 private String
operator =
"=";
176 private boolean calculating =
true;
180 setLayout(
new BorderLayout());
181 display.setEditable(
false);
182 add(display,
"North");
183 JPanel panel =
new JPanel();
184 panel.setLayout(
new GridLayout(4, 4));
187 JButton b =
new JButton(label);
190 b.addActionListener(
this);
192 add(panel,
"Center");
198 String cmd = evt.getActionCommand();
199 if (
'0' <= cmd.charAt(0) && cmd.charAt(0) <=
'9' || cmd.equals(
"."))
203 display.setText(cmd);
207 display.setText(display.getText() + cmd);
217 display.setText(cmd);
230 x = Double.parseDouble(display.getText());
232 catch (NumberFormatException e)
246 private void calculate(
double n)
262 display.setText(
"Error");
263 throw new IllegalArgumentException(
"Division by zero");
274 display.setText(
"OF");
275 throw new OverflowException();
277 display.setText(
"" + result);
286 display.setText(
"0");
293 public static class OverflowException
extends RuntimeException
298 private static final long serialVersionUID = 1L;
303 public OverflowException()
312 public static class UnderflowException
extends RuntimeException
317 private static final long serialVersionUID = 1L;
322 public UnderflowException()
void reset()
Puts the object back into its initial state.
boolean m_checkFormat
A flag specifying if the calculator checks the format of numbers.
Signals that an object can be put back into its initial state.
Performs monkey testing by interacting with a component.
boolean m_hasOverflow
A flag specifying if the calculator produces an overflow exception.
Calculator disableNumberFormatException()
Instructs the calculator to check the format of numbers and ignore parsing errors.
static void main(String[] args)
A main method allowing the calculator to be run as a stand-alone application.
Calculator()
Creates a new calculator window.
The actual panel containing the interface of the calculator.
void actionPerformed(ActionEvent evt)
void reset()
Puts the object back into its initial state.
Map< String, JButton > m_buttons
A map associating each button to its label.
CalculatorPanel m_panel
The calculator panel contained within the frame.
Classes that enable Synthia to operate as a fuzz testing tool.
Calculator hasOverflow()
Instructs the calculator to throw an OverflowException when producing a number over 100,...
JButton getButton(String label)
Gets the button instance with given label.
static final String[] BUTTON_LABELS
The array of button labels.