# Lab-5502: Your First Mobile Game

Expected Duration: 100 minutes
Contacts: Andrey Korostelev and Ivan Sidorkin

Introduction | Exercise 0 | Exercise 1 | Exercise 2 | Exercise 3 | Exercise 4 | Exercise 5 | Summary
Introduction Background Information Steps to Follow Summary ## Exercise 1: Create MIDP Application (15 minutes) In this exercise we will create a new Mobile Information Device Profile (MIDP) application using NetBeans Java ME support. We will see how the IDE's Java ME Visual Designer simplifies the creation of mobile application workflows. ### Background Information NetBeans Mobility makes it easy for programmers to start developing for the Java ME platform quickly, even if you've only had Java SE programming experience. If you are programming mobile devices for the first time, you can just think of Java ME as having a more limited version of the Java SE API, and let NetBeans take care of Java ME specific issues. Though there are more differences to Java ME than just a smaller API, it's not necessary to know all of them before producing a working mobile application. To help you get started, here are some terms that are used throughout this document: Java ME – Java Platform, Micro Edition is the Java platform created to run on small devices such as cell phones or PDAs, but Java ME is also used in various types of embedded systems. The configuration, profile, and optional packages are what comprise the Java ME platform. CLDC – Connected Limited Device Configuration is a Java ME configuration that is currently most often used on mobile phones. It contains a runtime environment and a core API that are appropriate for the limited processor speed and memory size of mobile devices. MIDP – Mobile Information Device Profile is the set of APIs that provide higher level functionality required by mobile applications like displayable components and network communication. MIDlet – A class required by all MIDP applications. It acts as the interface between the application and the device on which it is running. Similar to a main class in a Java SE project. Emulator – a tool which can run your mobile applications. The emulator is designed to mimic the behavior of the real phone it is emulating. Platform – a Java development kit used to build and run the project in the NetBeans IDE. For Mobile projects this usually means an emulator, code building tools and various JARs to implement the Java ME API. WTK – Sun Java Wireless Toolkit for CLDC 2.5.2 - a reference implementation of Java ME's CDLC configuration and MIDP profiles bundled with the NetBeans Java ME module. It also includes various code building tools and sample appolications. JSR172 – J2ME Web Service API. Optional J2ME package defining the API for connecting to a web service. ### Steps to Follow Step 1: Creating NetBeans Java ME Project If NetBeans is not already running, start it. Open the New Project wizard. To do it click the New Project... button on the toolbar or select `File > New Project...` from the main menu. Select `Java ME > Mobile Application` as project type and click `Next`. Type `MobileGame` as the project name and uncheck the `Create Hello MIDlet` box and click `Finish` to create the project. Step 2: Defining the application workflow with the Visual Designer Expand the `Source Packages` node in the `Project tree` and select `<default package>` Add a new java package named `game` to source packages. To do it select `New > Java Package...` in contextual menu of the `<default package>` node. In the `New Java Package` dialog enter the package name, `game` and click `Finish`. Add a new VisualMIDlet to the game package. You can use the default name. The new MIDlet will be opened in Visual Mobile Designer's Flow view by default. The Mobile Device element representing the MIDLet is always shown in the Flow view. The Visual Designer is a drag-n-drop interface that enables us to add new displayables and manage the application workflow. Add the SVG Form to the application by dragging it from the `SVG Components` category of the palette. To make SVG Form the first displayable that will be shown on the device screen after the MIDlet is started, Add a connection from the `Started` action of the Mobile Device to svgForm by dragging the mouse with the left button pressed from the `Started` action to the svgForm component The next element to add to the application workflow is the game, but until we import the game classes, we can't display them in the Visual Designer. For the moment we'll postpone this step until Exercise 3. After the game is finished, we will show the winner using another SVG form. Add the second SVG form to the flow view. ### Summary In this exercise, you saw how to rapidly create a mobile application from scratch using the Visual Movile Designer in NetBeans. In the next Exercise we will create SVG images for displaying the SVG forms we created. Back to top Next exercise