|
Free
Java
Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
|||||
Coding the Clear Button of our Java Calculator |
||||||
|
Java Calculator Project: 1 2 3 4 5 6 7 8 9 10 The only thing left to code for now is the Clear button. For this, we need to clear the total2 variable and set the text in the text field to a blank string. In Design view, double click your Clear button to create the code stub. Now add these two lines to your Clear button: total2 = 0; Once you've added the lines, you can try your calculator out. Run the programme and try adding numbers. You should find that your calculator adds up fine.
Exercise
Congratulations - you have now written a Java calculator programme! OK, it can only add up, but it's a start. What we'll do now is to make it subtract, divide and multiply.
<-- The Equals Button | Subtract, Divide, Multiply Buttons --> <--Back to the Java Contents Page View all our Home Study Computer Courses
|