Java Reference
In-Depth Information
4. Click on the Create Project button. In the following screen, change
the Target Platform to JTWI and click OK.
Your project is now created, so it's time to write our first MIDlet
application. Open a text editor and type in the following code:
package example;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class HelloWorldMIDlet extends MIDlet
private Form form = null;
public HelloWorldMIDlet() {
form = new Form("HelloWorld Form");
form.append("Hello, World!");
form.append("This is my first MIDlet!");
} public void destroyApp(boolean arg0) throws MIDletStateChangeException {}
public void pauseApp() {}
public void startApp() throws MIDletStateChangeException {
In the constructor, we create a new Form object and append some
text strings to it. Don't worry about the details of the Form class. For now
it's enough to know that Form is a UI class that can be used to group
small numbers of other UI components. In the startApp() method, we
use the Display class to define the form as the current UI component
being displayed on the screen.
Build your MIDlet with the following steps:
Save the file, with the name ,inthe
source code folder created by your installation of the Wireless Toolk-
it. Usually its path is
< home > \ j2mewtk \ 2.5.2 \ apps \ Hello-
World \ src \ example ,where
is your home directory. In
Windows XP systems, this value can be found in the USERPROFILE
environment variable; in Linux, it is the same as the home folder.
You must save the .java file in the src \ example folder because
this MIDlet is in the example package.
< home >
Switch back to the WTK main window and click Build. The WTK
compiles and pre-verifies the HelloWorldMIDlet class, which is
then ready to be executed.
3. Click on Run. You are presented with a list of MIDlets from the
packaged suite, which are ready to be run. As our test suite only has
one MIDlet, click on its name and it is executed on the mobile phone
emulator (see Figure 2.4).
Search WWH ::

Custom Search