OK, first.
1. Object Oriented programming ... break your programming down into "classes", related to logical sets of data, and the methods that manipulate that data.
2. Focus on building the LOGICAL classes, separate from your UI.
So, don't write a dozen input hanlders doing all your math ... write a dozen input handlers calling methods, which do the math ... now in a real program there is nothing wrong with event handlers the size of yours (3 lines long) ... but since this is half the logic of your program, you are not solving your problem cleanly.
There are at least 5-10 reasonable and very different ways to solve the problem you are asking (and millions of smaller varieties). Programming is about thinking through problems and we all think different (like musicians or painters) ... so all we can do is either show you how we would do it and hope you can generalize, or show you general techniques and hope you can apply them specifically.
But to help you out a bit ... first a thought, try to store your variables in a "natural" manner completely not realated to your UI. what is "natural" depends on you point of view. If you were implementing a more simple calculator "natural" might be:
a variable called something like "accumulator", "currentValue", "register" or the like ... which holds the total so far ... ie "0" when reset, and the number that is displayed after users press the "=" etc.
a variable called "operator", "pendingOperation", "state" or some such .... which holds the operation the user has requested after the press something like "+". and would be able to detect the when there isn't one (ie if the user types "3+3=" after the "=" the pending operation is null, so that you can tell if the user then types "53" then are doing the "set value to ..." operation, which doesn't care what the previous value was ... wheras if they type "+" then "53" they are doing the "add value ..." operation which does use the previous / current value.
now of course, i've only hinted at posibilities ... over about 17 years of programming, I've written calculators for examples, for fun, and for trying out new programming languages or ideas probably 7 or 8 times ... none are just like I described, but that's the point, its just a program to think up however you like ... and then work through it tell it makes since AND works.
Good luck.
Edited by Xai, 29 June 2012 - 10:33 PM.