![]() |
![]() |
![]() |
![]() |
Creating an Exit button
Let's add one more thing to this program... a way to close it. By default, the user can exit by tapping the Home button. It's a good idea to have a button in your program that will exit as well. We will do this by creating a new button which will do this.
- On the Object Palette, make sure that the first page, 'Kjava', is visible. (If not, click the mouse button on the 'Kjava' Tab.)
- Click the first icon, named 'Button', with the mouse. (It should now appear depressed. Also, the title bar of the Object Palette will reflect your selection.)
- Click on the right side of the Emulator, opposite the 'compute tip' button. You should see a new button appear on the screen.
- The new button's property sheet will be shown in the Simplicity Composer. Change the Button text from 'button6' to 'Exit'.
- Select the second page from the properties notebook, labelled 'penDown'.
We will use the Code Sourcerer again to write the code which will quit the application.
- Press the Code Sourcerer button toward the top of the 'penDown' page.
- A dialog appears with a list of choices. We want to quit the application, so choose the second option from the bottom, 'Java system operations...'. Press Next.
- The Code Sourcerer asks you which system operation you want to do. You want to exit the program normally, so choose 'Exit the program with termination code' and leave the default value of '0'. Press Done.
The following code should have appeared in the Pen Down page.
This will cause the application to quit. When you press this button inside the emulator, you will see a window titled 'Program Terminated' with the message 'exit code 0' to let you know that it worked, but the Emulator itself will not actually be closed.
You have now finished designing your tip calculator. Save your work by choosing Exit from the File menu in the Composer. Choose Yes when asked if you want to save your changes.
Data Representations, Inc. http://www.datarepresentations.com support@datarepresentations.com sales@datarepresentations.com |
![]() |
![]() |
![]() |
![]() |