|
Setup
How to setup your J2ME development environment.
Featured IntroductionThis is a setup guide that will get your J2ME development environment up and running. At the end you will run the J4ME examples. It is assumed you already know Java and use Eclipse. If you don't know Java you can still follow the setup, but you'll need to look elsewhere to learn the basics of writing J2ME code. If you don't use Eclipse please post on the discussion board how you setup your environment. Sun WTK5 minutes The Sun Java Wireless Toolkit (WTK) for CLDC emulates a J2ME environment on your computer. There are other emulation environments available, but most are built from the Sun WTK.
EclipseIf you do not already have Eclipse download and install it. The base installation package for Java development is all you need. ProGuard3 minutes ProGuard is an obfuscater for Java code. It is especially helpful for J2ME because it shrinks the final Jar size significantly and optimizes the code. This means it loads and runs faster on phones. Part of the obfuscation process is removing unused classes. If you do not use part of the J4ME library, obfuscation will remove that class from your Jar.
J2MEUnit3 minutes J2MEUnit is a port of JUnit to the J2ME environment. J2ME does not support reflection so J2MEUnit is basically the same but with an extra method that specifies your tests. J4ME uses J2MEUnit for its tests. Any fixes you submit should include a J2MEUnit test case to make sure it will always behave as you expect. Also your own project should use J2MEUnit for testing.
Antenna(Optional) 3 minutes If you use Ant, you'll want Antenna. It is a collection of Ant tasks for J2ME. But you will be able to package your J2ME applications from Eclipse without it.
EclipseME20 minutes EclipseME is the plug-in for J2ME development. It makes Eclipse properly package J2ME applications and debug them in the emulators.
J4MEBy this point you have a complete J2ME environment. After this section you'll be running J4ME's examples and be ready to use J4ME in your own applications. Install J4ME2 minutes
Add J4ME to the Eclipse Workspace5 minutes
Run the Examples5 minutes
Hello WorldAt this point you have setup your J2ME environment and looked at the J4ME library. This section lets you build your very first J2ME application. Creating a J2ME Project3 minutes
J2ME Coding5 minutes
import javax.microedition.lcdui.*;
import org.j4me.ui.*;
import org.j4me.ui.components.*;
/**
* A screen that displays "Hello World".
*/
public class HelloWorldScreen extends Dialog
{
/**
* Constructor.
*/
public HelloWorldScreen ()
{
// The title across the top of the screen.
//setTitle( "J4ME" );
// Set the menu text at the bottom of the screen.
// "Exit" will appear on the left and when the user presses the phone's
// left menu button declineNotify() will be called. When the user
// presses the right menu button acceptNotify() will be called.
setMenuText( "Exit", null );
// Add a UI component.
Label lbl = new Label("Hello World!");
lbl.setHorizontalAlignment( Graphics.HCENTER );
append( lbl );
}
/**
* Called when the user presses the left menu button to "Exit".
*/
public void declineNotify ()
{
// Exit the application.
HelloWorldMidlet.exit();
// Continue processing the event.
super.declineNotify();
}
}import javax.microedition.midlet.*;
import org.j4me.ui.*;
/**
* The entry point for the application.
*/
public class HelloWorldMidlet extends MIDlet
{
/**
* The one and only instance of this class.
*/
private static HelloWorldMidlet instance;
/**
* Constructs the midlet. This is called before <code>startApp</code>.
*/
public HelloWorldMidlet ()
{
instance = this;
}
/**
* Called when the application is minimized. For example when their
* is an incoming call that is accepted or when the phone's hangup key
* is pressed.
*
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp ()
{
}
/**
* Called when the application starts. Shows the first screen.
*
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp () throws MIDletStateChangeException
{
// Initialize the J4ME UI manager.
UIManager.init( this );
// Change the theme.
//UIManager.setTheme( new org.j4me.examples.ui.themes.RedTheme() );
// Show the first screen.
HelloWorldScreen screen = new HelloWorldScreen();
screen.show();
}
/**
* Called when the application is exiting.
*
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp (boolean arg0) throws MIDletStateChangeException
{
// Add cleanup code here.
// Exit the application.
notifyDestroyed();
}
/**
* Programmatically exits the application.
*/
public static void exit ()
{
try
{
instance.destroyApp( true );
}
catch (MIDletStateChangeException e)
{
// Ignore.
}
}
}Congratulations! You have written and run your first J2ME application. |
it is not working, i follow above all steps but it is not running in emulator and it shows some errors,how can i get my code like error free,please help me
Make sure that the 2 source files are in the same package.
The emulator crashed immediately after launch. No error messages. Any suggestions?
i do all these steps but the j2me emulater is not run just run the code plese give any suggestion that how to run emulater
Here’s a tool that lets your create location-based applications such as Distance Search, Map Mashups, and Automatic Geocoding without coding http://blog.caspio.com/web_apps/create-location-based-applications-with-caspio/