Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing value in java REVISED with full code
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5916497/passing-value-in-java-beginner-stuff">Passing value in java BEGINNER stuff</a> </p> </blockquote> <p>I thought i would upload the full code as it may make things clearer basically what i want is operation to store either + - or * when these buttons have been clicked then i want this value to be stored so that when the = button is clicked it will then go through another if statment to work out which operation should happen to the numbers being used. Hopefully this will make things clearer and thanks in advance</p> <pre><code> JButton operand = (JButton) calculate.getSource(); String flip = operand.getLabel(); String operation = ""; String operation1(operation); System.out.println(operation); String value1 = (box1.getText()); String value2 = (box2.getText()); box1.setText(box1.getText() + operand.getLabel()); if (flip == "C") {box2.setText(""); box1.setText(""); } if (flip == "!") {int intValueNeg = Integer.parseInt(value1); int negateIntValue = intValueNeg * (-1); String negativeInt = Integer.toString(negateIntValue); box1.setText(negativeInt);} if (flip == "+" || flip == "-" || flip == "*" ) { box2.setText(value1); box1.setText(""); operation = flip; } if (flip == "=") { int intValue1 = Integer.parseInt(value1); int intValue2 = Integer.parseInt(value2); if (operation == "+") { int totalValue = intValue1 + intValue2; String totalResult = Integer.toString(totalValue); box1.setText(totalResult); box2.setText("0"); } if (operation == "-") { int totalValue = intValue2 - intValue1; String totalResult = Integer.toString(totalValue); box1.setText(totalResult); box2.setText("0"); } if (operation == "*") { int totalValue = intValue1 * intValue2; String totalResult = Integer.toString(totalValue); box1.setText(totalResult); box2.setText("0"); } } } </code></pre>
 

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