Getting Started

In this getting started tutorial, Im going to show you how to create a simple application using Flemil and the Sun's WTK emulator. The application will be a simple window, with a title and a few controls inside.

Build Your First Application

Open the SUN WTK emulator and create a new project. For this example, I will call the project HelloFlemil and call the project MIDlet FlemilMIDlet. This is showb below
New Project
Im going to be creating the project to target devices with both CLDC 1.1 and CLDC 1.0 as well as MIDP 2.0 or MIDP2.1. So on the project settings dialog that follow the project name and project MIDlet specification dialog, select a custom API as ahown in the figure below.
Project Settings
After you have selected "OK" you will see some output on the console of the WTK console window about the status of the just created project. Below is what I get on my device Image for the resulting project settings In the diagram you can see that three directories have been created and associated with the project. These are
The projects source files folder
Place Java source files in "/home/solomon/j2mewtk/2.5.2/apps/HelloFlemil/src"
The projects resource files folder
Place application resource files in "/home/solomon/j2mewtk/2.5.2/apps/HelloFlemil/res"
The projects library files folder
Place application library files in "/home/solomon/j2mewtk/2.5.2/apps/HelloFlemil/lib"
To use the Flemil library, simply place the downloaded jar file into the "The projects library files folder". We have now made the Flemil library classes available to our source code and our project. So we now go ahead and create the .java file for the sample application. We will place the MIDlet java file in the default package since we did not specify a package when specifying the project MIDlet name. In a real application, it is a good practice to place your files in packages and avoid the usage of default package like we did here. We will need to call the file FlemilMIDlet. Please replace this with the name you specified for the MIDlet in the first step above if you used a different name from FlemilMIDlet. place the FlemilMIDlet.java file in the "The projects source files folder" folder. Open the java file with a text editor. We are now going to create a new MIDlet from scratch that will make use of Flemil UI library.
Enter the following code into FlemilMIDlet.java and save the file
import javax.microedition.midlet.MIDlet; 
import com.flemil.control.GlobalControl; 
import com.flemil.event.MenuCommandListener;
import com.flemil.ui.component.Label;
import com.flemil.ui.component.Menu;
import com.flemil.ui.component.MenuItem;
import com.flemil.ui.component.Panel;
import com.flemil.ui.component.ScreenWindow;

public class FlemilMIDlet extends MIDlet {
	private ScreenWindow firstWindow=null;
	public FlemilMIDlet()
	{
		GlobalControl.init(this);
		GlobalControl.getControl().setFading(true);
		firstWindow=new ScreenWindow("Hello Flemil");
		firstWindow.getContentPane().setAlignment(Panel.SPAN_FULL_WIDTH|
				Panel.CENTER_VERTICAL_ALIGN);
		Label welcomeLabel=new Label("Hallo There. "+
			"Im a Label that "+
			"Spans the full width "+
			"of the window and  centered vertically :)");
		firstWindow.getContentPane().add(welcomeLabel);
		MenuCommandListener listener=new MenuListener();
		for(int i=0;i<4;i++)
		{
			MenuItem item=new MenuItem("Item "+(i+1));
			item.setListener(listener);
			firstWindow.getMenu().add(item);	
		}
		GlobalControl.getControl().setCurrent(firstWindow);
	}
	public void startApp() {  
    		
	} 
	public void pauseApp() 
	{
	}
	public void destroyApp(boolean unconditional) 
	{
	}
	class MenuListener implements MenuCommandListener
	{
		public void commandAction(MenuItem item) {
			GlobalControl.getCurrentMIDlet().notifyDestroyed();
		}
	}
}
					

That is all we need to get the application ready. Go the WTK and press the build button. The build should succeed. If it fails, make sure the library is in the lib folder and that you have included the correct jar file. For example make sure the jar file has the .jar extension and that it has the name like Flemil-1.0.0.jar.

If your build succeeded, press the "Run" button on the WTK emulator and the application will run. This application is a window that has a title "Hello Flemil", a centrally located label inside this window and four MenuItems which closes tha application if any of them is selected.

Its that simple to get started with Flemil. I hope you find this interesting and will explore more to do awesome things with Flemil.