Exercise 2: Create an Application UI with SVG Rich ComponentsThis exercise provides a streamlined introduction to the SVG UI Rich Components. For more details, please see the in the Netbeans Visual Mobile Designer Wiki page. In this exercise we are going to build a basic SVG-based application UI. Though the application is quite simple, it will show you how to create a new Java ME application, how to import SVG images from the SVG Composer into a visual MIDlet and how to run the project on a MIDP device emulator. Background InformationIntroduction to the NetBeans Visual Mobile DesignerOne of the key features of NetBeans is the mobile application development support provided by the Visual Mobile Designer. This tool enables rapid design and development of mobile applications (MIDlets) by letting users drag-and-drop components into a Screen Designer, where the developer designs the individual UI screens, and the Flow Designer where the developer specifies how the individual screens are connected together by defining the application flow. The Visual Mobile Designer automatically generates compact Java code, which can be further enhanced manually in the source code editor. In NetBeans 6.5 a new feature was introduced that enables developers to create UIs with SVG technology in a way similar to Java SE Swing. To get us started quickly we will begin by opening a prepared ContactBrowser project that we will add to in the following excercises. Steps to FollowStep 1: Open the prepared ContactBrowser Java ME project
Step 2: Create an SVG UI using the SVG Composer In this step we will use the SVG Composer to create an SVG UI by editing SVG images and adding the additional UI Components our application needs.
Step 3: Creating a MIDlet in Visual Mobile Designer The SVG Rich UI components framework is split into two parts:
We have already covered the SVG Composer and snippets, so our next step is to look at the runtime libraries in the Visual Mobile Designer which help to merge the SVG images with the application logic in the Java ME source code.
Step 4: Creating the application flow Using the Visual Mobile Designer in NetBeans IDE In this part we are going to create the application flow using the Flow view of Visual Mobile Designer.
Source Code Generated by the Visual Mobile Designer We now have a fully functional SVG-based UI and application flow that's ready to run on the emulator. Before we do that let's look at the source code generated by the Visual Mobile Designer. To see the source code of an application switch to Source view. As you can see on the screen shot below, some parts of source code are in "guarded" blocks, which means that it is not possible to edit these areas within the source code editor. The guarded blocks of source code are generated by actions taken when using the Visual Mobile Designer's Flow, Screen or Screen Designer view.
Next lets look at the mechanism that binds SVG XML UI Component snippets with Java ME runtime libraries. In the example below you can
see how the SVG Button snippets are bound to Java ME objects. The SVG Component is recognized based on the XML snippet ID, in this example,
it is Step 5: Running the Application Launching the program on the WTK 2.5.2 device emulator To test the Contact Browser on the emulator make sure that you have the Sun Java Wireless Toolkit 2.5.2 installed and registered in the IDE. You can check this by opening the Tools > Java Platforms menu and verifying that the WTK is in the Platforms window under the J2ME category in the Java Platform Manager dialog. In the menu Run Main Project (F6) and after emulator launches you can see and test your UI. We have not implemented the application logic yet, but can verify that the UI displays as expected based on the work done in the Visual Mobile Designer.
SummaryIn this exercise you created an SVG UI using SVG UI Rich Components. You learned the fundamental uses for the SVG Composer and the Visual Mobile Designer. You also learned how SVG UI Rich Components work and how to run and verify your design in the application emulator. In the following exercise we will work more with the source code of the application and create the core functionality of Contact Browser application. |
|
| ||||||||||||