+ 2

Which is the best alternative solution?

https://code.sololearn.com/cPWEJt84o54U/?ref=app

1st Sep 2017, 11:04 PM
Ardu
Ardu - avatar
3 Answers
+ 4
You could use an array, where the index of the button + 1 is the amount you increase myFrame.res by. Something like: myFrame.res += indexOf(myArray, myButtaction) + 1; In the actionPerformed method. Or, some sort of dictionary/struct class so each button has a number that would indicate how much you increase the value by.
2nd Sep 2017, 1:31 AM
Rrestoring faith
Rrestoring faith - avatar
+ 2
For what?
1st Sep 2017, 11:50 PM
Rrestoring faith
Rrestoring faith - avatar
0
I want to add two numbers. When i push the button 1 and button 2 the result would be 3 (1+2=3). The variable res (result) is out of public void actionPerformed (ActionEvent e). Which is the best way to write this code?
1st Sep 2017, 11:52 PM
Ardu
Ardu - avatar