Comment and clean up the Window class.

This commit is contained in:
Danila Fedorin 2017-07-26 19:10:55 -07:00
parent 15d7dbd30e
commit bc72b4da8a
1 changed files with 16 additions and 3 deletions

View File

@ -18,18 +18,27 @@ import java.awt.event.MouseEvent;
public class Window extends JFrame { public class Window extends JFrame {
private static final String CALC_STRING = "Calculate"; private static final String CALC_STRING = "Calculate";
private static final String SELECT_STRING = "Select";
private static final String SYNTAX_ERR_STRING = "Syntax Error"; private static final String SYNTAX_ERR_STRING = "Syntax Error";
private static final String EVAL_ERR_STRING = "Evaluation Error"; private static final String EVAL_ERR_STRING = "Evaluation Error";
private static final String NUMBER_SYSTEM_LABEL = "Number Type:"; private static final String NUMBER_SYSTEM_LABEL = "Number Type:";
private static final String FUNCTION_LABEL = "Functions:"; private static final String FUNCTION_LABEL = "Functions:";
/**
* Array of Strings to which the "calculate" button's text
* changes. For instance, in the graph tab, the name will
* be "Graph" and not "Calculate".
*/
private static final String[] BUTTON_NAMES = { private static final String[] BUTTON_NAMES = {
CALC_STRING, CALC_STRING,
CALC_STRING CALC_STRING
}; };
private static boolean[] BUTTON_ENABLED = { /**
* Array of booleans that determine whether the input
* field and the input button are enabled at a particular
* index.
*/
private static boolean[] INPUT_ENABLED = {
true, true,
false false
}; };
@ -131,6 +140,10 @@ public class Window extends JFrame {
inputField.setText(""); inputField.setText("");
}; };
/**
* Array of listeners that tell the input button how to behave
* at a given input tab.
*/
private ActionListener[] listeners = { private ActionListener[] listeners = {
evaluateListener, evaluateListener,
null null
@ -205,7 +218,7 @@ public class Window extends JFrame {
pane.add("Settings", settingsPanel); pane.add("Settings", settingsPanel);
pane.addChangeListener(e -> { pane.addChangeListener(e -> {
int selectionIndex = pane.getSelectedIndex(); int selectionIndex = pane.getSelectedIndex();
boolean enabled = BUTTON_ENABLED[selectionIndex]; boolean enabled = INPUT_ENABLED[selectionIndex];
ActionListener listener = listeners[selectionIndex]; ActionListener listener = listeners[selectionIndex];
inputEnterButton.setText(BUTTON_NAMES[selectionIndex]); inputEnterButton.setText(BUTTON_NAMES[selectionIndex]);
inputField.setEnabled(enabled); inputField.setEnabled(enabled);