Note that there are some explanatory texts on larger screens.

plurals
  1. PODo i need to use a method or can I simply pass an operation when it is changed?
    primarykey
    data
    text
    <p>Is it possible for me to pass the operation string back from when a <code>+</code>, <code>-</code> or <code>*</code> operation occurs so that it saves it as operation and then I can move on to when I press <code>=</code> or is this simply impossible?</p> <h3>Code part 1:</h3> <pre><code>public void actionPerformed(ActionEvent calculate) { JButton operand = (JButton) calculate.getSource(); String flip = operand.getLabel(); String operation = ""; System.out.println(operation); String value1 = (box1.getText()); String value2 = (box2.getText()); box1.setText(box1.getText() + operand.getLabel()); if (flip.equals("C")) { box2.setText(""); box1.setText(""); } if (flip.equals("!")) { int intValueNeg = Integer.parseInt(value1); int negateIntValue = intValueNeg * (-1); String negativeInt = Integer.toString(negateIntValue); box1.setText(negativeInt); } if (flip.equals("+")) { box2.setText(value1); box1.setText(""); operation = operand.getLabel(); } if (flip.equals("-")) { box2.setText(value1); box1.setText(""); operation = operand.getLabel(); } if (flip.equals("*")) { box2.setText(value1); box1.setText(""); operation = operand.getLabel(); } if (flip.equals("=") &amp;&amp; operation.equals("+")) { int intValue1 = Integer.parseInt(value1); int intValue2 = Integer.parseInt(value2); int totalValue = intValue1 + intValue2; String totalResult = Integer.toString(totalValue); box1.setText(totalResult); box2.setText("0"); } if (flip.equals("=") &amp;&amp; operation.equals("-")) { int intValue1 = Integer.parseInt(value1); int intValue2 = Integer.parseInt(value2); int totalValue = intValue2 - intValue1; String totalResult = Integer.toString(totalValue); box1.setText(totalResult); box2.setText("0"); } if (flip.equals("=") &amp;&amp; operation.equals("*")) { int intValue1 = Integer.parseInt(value1); int intValue2 = Integer.parseInt(value2); int totalValue = intValue1 * intValue2; String totalResult = Integer.toString(totalValue); box1.setText(totalResult); box2.setText("0"); } } } </code></pre> <h3>Code part 2:</h3> <pre><code>box2 = new JTextField (10); b.add(box2); Blackbelt.add(a, BorderLayout.NORTH); Blackbelt.add(c, BorderLayout.CENTER); Blackbelt.add(b, BorderLayout.SOUTH); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload