Before reading this, you should have downloaded Netbeans IDE 6.1, choose the Mobility version or the All version.
When creating a J2ME application, I usually separate my MIDlet class, view-controller classes and model classes.
I do not separate View and Controller since normally my views only have a couple of controls and I find it more organized that way.
Link for the source code at the end of the tutorial.
Step 1. Create a new Project By File>New Project
Click Mobility from the Categories and MIDP Application from Projects.
Step 2. Write any Project Name and select a project location then click the Next Button.
Step 3. Select CLDC 2.0 and MIDP 2.0
Step 4. Click Finish. Delete all generated .java files as we will not be using the WYSIWYG editor.
Then create two classes, HelloWorldForm.java and HelloWorldMIDlet.java
You should have the following files on your Project Tab.
Step5. Writing the HelloWorldMIDlet.java code.
PauseApp, destroyApp and startApp are the abstract classes of the MIDlet class that needs to be implemented. I added two methods to be used by the UI class, showScreen(Displayble d) and showScreenAndAlert(Alert a, Displayble d).
The code in startApp() will be discussed after the next step.
Step 6. Coding the HelloWorldForm.java.
As you may have noticed, the MIDlet class is passed to the constructor, I find this useful in creating a apps with a lot of forms. Further, the MIDlet class may also be used to store Application sessions data, also handling unexpected application problems.
The initComponents() method is where the UI Components are initialized and added to the Form.
If you do not want the controller and the view to be on the same class, you may create, or pass in the constructor a class that implements the CommandListener interface.
On the code, instead of setCommandListener(this), just replace this with a CommandListener instance.
Step 7. Building and Running.
Source Code
Java Programming Blog where I can post my interest, problems that I had solved in the past for my personal reference.
Sunday, September 28, 2008
Subscribe to:
Post Comments (Atom)
Find Properties for Sale or Rent in the Philippines on your Android Phone
Tutorial List
- GWT : Creating a File Hosting App using Google App Engine
- Stock Market Tutorial
- Android Application : Beer Radar
- Android Application : Beer Radar Server Component
- Android Camera Tutorial
- Android Custom Database List Adapters
- Android GPS Tutorial
- Android Hello World Tutorial
- Android Map Tutorial
- Android Networking Tutorial
- Android Parsing JSON Tutorial
- Android SQLite AutoIncrement
- Android SQLite Tutorial
- AppEngine: Generating JSON
- Beer Radar Web Application
- Google App Engine - Spring Integration Issues
java.padawan@androidph.com
No comments:
Post a Comment