|
|
||
| You are here: | ||
|
source: AddSub.java
The Class has the same types of awt object as before. Two TextFields hold the user input. Two Buttons for the choices; an answer Label.
Does the same as init in previous examples.
Since we have two buttons, both get an actionListener.
Local identifiers (sometimes called variables) hold temporary values needed by this method . The if statement has a condition (must evaluate either to true or false). If true the first part is done, otherwise the else part is done. The Label text is set to the answer, the + converts the int to a String automatically. |
Related pages: [ selection | quizzes ] /** Calculator // check which button was pressed etc. The final else block in this chain is done when no other options are true. You can use the howToImproveLayout techniques to add the buttons to a panel to make them look nicer. PressMe Re-visited if (name.equals("Ginger")) and not if (name=="Ginger") Related: [ Java Core | Selection Quizzes | previous Selection | next:Repetition ] |
Teaching notes After looking at this example students should be able to attempt most of the exercises. |
|
|
|||
|
Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified: May 31, 2009 |