Skip to content

Commit

Permalink
fixed evaluation frame
Browse files Browse the repository at this point in the history
  • Loading branch information
krasko committed Nov 15, 2012
1 parent 0f51f9b commit 0675195
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/gui/EvaluationFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class EvaluationFrame extends JFrame {

private String[] names;
private double[] values;
private JTextField[] valueFields;

private TeXCalculator calc = new TeXCalculator();

Expand All @@ -47,26 +48,24 @@ public void windowClosing(WindowEvent e) {

names = calc.valsRequiredAsArray(formulaAST);
values = new double[names.length];
valueFields = new JTextField[names.length];

for (int i = 0; i < names.length; ++i) {
final JLabel variableLabel = new JLabel();
variableLabel.setIcon(GuiUtils.generateIcon(names[i] + " ="));

final JTextField valueText = new JTextField();
valueText.setText(String.valueOf(values[i] = calc.getVal(names[i])));
calc.setVal(names[i], calc.getVal(names[i]));
final JTextField valueText = valueFields[i] = new JTextField();
valueText.setText(String.valueOf(calc.getVal(names[i])));

add(variableLabel, new GridBagConstraints(0, i + 1, 1, 1, 0, 0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, GuiUtils.INSETS, 0, 0));
add(valueText, new GridBagConstraints(1, i + 1, 1, 1, 0, 0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, GuiUtils.INSETS, 0, 0));

final int _i = i;
valueText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
values[_i] = Double.parseDouble(valueText.getText());
updateResult();
} catch (Exception ex) {
//do nothing
Expand All @@ -86,6 +85,7 @@ public void actionPerformed(ActionEvent e) {

private void updateResult() {
try {
for (int i = 0; i < names.length; ++i) values[i] = Double.parseDouble(valueFields[i].getText());
calc.setContext(names, values);
formulaLabel.setIcon(GuiUtils.generateIcon(formula + " = " + calc.calculate(formulaAST)));
} catch (Exception e) {
Expand Down

0 comments on commit 0675195

Please sign in to comment.