mirror of
https://github.com/DanilaFe/abacus
synced 2025-01-09 23:58:09 -08:00
Add Stop Button
This commit is contained in:
parent
699ba9e193
commit
dd915136c6
@ -16,12 +16,15 @@ import java.awt.event.MouseEvent;
|
|||||||
*/
|
*/
|
||||||
public class Window extends JFrame {
|
public class Window extends JFrame {
|
||||||
|
|
||||||
|
private boolean contComputation;
|
||||||
|
|
||||||
private static final String CALC_STRING = "Calculate";
|
private static final String CALC_STRING = "Calculate";
|
||||||
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:";
|
||||||
|
private static final String STOP_STRING = "Stop";
|
||||||
|
private static final String STOPPED_TEXT = "Stop";
|
||||||
/**
|
/**
|
||||||
* Array of Strings to which the "calculate" button's text
|
* Array of Strings to which the "calculate" button's text
|
||||||
* changes. For instance, in the graph tab, the name will
|
* changes. For instance, in the graph tab, the name will
|
||||||
@ -90,7 +93,10 @@ public class Window extends JFrame {
|
|||||||
* The "submit" button.
|
* The "submit" button.
|
||||||
*/
|
*/
|
||||||
private JButton inputEnterButton;
|
private JButton inputEnterButton;
|
||||||
|
/**
|
||||||
|
* The stop calculations button.
|
||||||
|
*/
|
||||||
|
private JButton inputStopButton;
|
||||||
/**
|
/**
|
||||||
* The side panel for separate configuration.
|
* The side panel for separate configuration.
|
||||||
*/
|
*/
|
||||||
@ -117,22 +123,39 @@ public class Window extends JFrame {
|
|||||||
/**
|
/**
|
||||||
* Action listener that causes the input to be evaluated.
|
* Action listener that causes the input to be evaluated.
|
||||||
*/
|
*/
|
||||||
|
private ActionListener stopListener = (event) -> {
|
||||||
|
contComputation=false;
|
||||||
|
};
|
||||||
private ActionListener evaluateListener = (event) -> {
|
private ActionListener evaluateListener = (event) -> {
|
||||||
|
contComputation = true;
|
||||||
TreeNode parsedExpression = abacus.parseString(inputField.getText());
|
TreeNode parsedExpression = abacus.parseString(inputField.getText());
|
||||||
if (parsedExpression == null) {
|
if(contComputation) {
|
||||||
lastOutputArea.setText(SYNTAX_ERR_STRING);
|
if (parsedExpression == null) {
|
||||||
return;
|
lastOutputArea.setText(SYNTAX_ERR_STRING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NumberInterface numberInterface = abacus.evaluateTree(parsedExpression);
|
NumberInterface numberInterface = null;
|
||||||
if (numberInterface == null) {
|
if(contComputation)
|
||||||
lastOutputArea.setText(EVAL_ERR_STRING);
|
numberInterface = abacus.evaluateTree(parsedExpression);
|
||||||
return;
|
if(contComputation) {
|
||||||
}
|
if (numberInterface == null) {
|
||||||
lastOutput = numberInterface.toString();
|
lastOutputArea.setText(EVAL_ERR_STRING);
|
||||||
historyModel.addEntry(new HistoryTableModel.HistoryEntry(inputField.getText(), parsedExpression, lastOutput));
|
return;
|
||||||
historyTable.invalidate();
|
}}
|
||||||
lastOutputArea.setText(lastOutput);
|
if(contComputation)
|
||||||
|
lastOutput = numberInterface.toString();
|
||||||
|
if(contComputation)
|
||||||
|
historyModel.addEntry(new HistoryTableModel.HistoryEntry(inputField.getText(), parsedExpression, lastOutput));
|
||||||
|
if(contComputation)
|
||||||
|
historyTable.invalidate();
|
||||||
|
if(contComputation)
|
||||||
|
lastOutputArea.setText(lastOutput);
|
||||||
|
else
|
||||||
|
lastOutputArea.setText(STOPPED_TEXT);
|
||||||
inputField.setText("");
|
inputField.setText("");
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,6 +190,7 @@ public class Window extends JFrame {
|
|||||||
|
|
||||||
inputField = new JTextField();
|
inputField = new JTextField();
|
||||||
inputEnterButton = new JButton(CALC_STRING);
|
inputEnterButton = new JButton(CALC_STRING);
|
||||||
|
inputStopButton = new JButton(STOP_STRING);
|
||||||
|
|
||||||
inputPanel = new JPanel();
|
inputPanel = new JPanel();
|
||||||
inputPanel.setLayout(new BorderLayout());
|
inputPanel.setLayout(new BorderLayout());
|
||||||
|
Loading…
Reference in New Issue
Block a user