Exercise 3: Adding application logic to the SVG User InterfaceIn this exercise we show how to use the Visual Mobile Designer to create and implement the application logic for the UI we created in the previous excercise. We will use some additional components and methods and finish by running the application in the Sun Java Wireless Toolkit 2.5.2 emulator. Background InformationLet's describe the things we will use in this exercice. The first is the SVG ListModel. This interface defines the methods components like the one SVGList uses to get the value of each cell in a list and the calculate the number of cells needed to display it. Logically the model is a vector, indices vary from 0 to ListDataModel.getSize() - 1. Any change to the contents or length of the data model must be reported to all of the SVGListDataListeners. If you are familiar with Swing's JList model, the SVGListModel should be easy to understand. We also have to understand how the Entry Point component works. The Entry Point component allows us to represent a method in a designed class. The method contains code specified by an action assigned to it, the "Entry Called" pin. This method is very useful when it is is necessary to execute code when switching between application screens, or in our case, to show the SVGButton logic in the Flow view of a Visual Midlet. Steps to FollowStep 1 Creating a Custom SVGList Model. In this step we are going to create our own implementation of SVGListModel. Our implemention of SVGListModel is an anonymous class inside of the
You can use the code completion feature in the IDE to create the code in the screenshot below, or use this code snippet and paste it into the editor. After pasting the code, right-click in the Source view window and choose Fix Imports from the contextual menu. Step 2: Next and Previous Button Logic In this step we will add logic for the SVGButtons which are a part of
the
Note: When using the Visual Mobile Designer to create mobile applications a lot of code is generated in guarded blocks that cannot be edited. These guarded blocks are displayed unexpanded with a dark gray background in the source editor.
Now we can start adding logic to the nextMethod and previousMethod
Next we need to make sure that the UI will be updated when
Step 2: Verifying the Next and Previous Button Logic We are ready to test our application in a Java ME device emulator. We are going to use the Sun Java Wireless Toolkit 2.5.2 DefaultColorEmulator that comes bundled in the NetBeans IDE installer.
SummaryIn this exercise we learned how to use the Visual Mobile Designer to implement application logic to support the UI we created in the previous excercise. We utilized the Entry Method and learned how to implement a custom SVG ListModel. We finished by testing our application in the Sun Java Wireless Toolkit 2.5.2 DefaultColorPhone emulator. In the following exercise, we will test the application UI in the emulator with touch-screen capabilities turned on by modifying the properties file in the WTK. |
|
|
||||||||||||