Hello (Canvas version)

From Mobile Application Design
Revision as of 02:22, 7 September 2007 by 125.103.222.73 (talk)
Jump to navigationJump to search

xalio philips canon wpdc800 hard disc firewire ecco la demo di doom 3 hp 1200d iniare sms testi canzoni tu corri home theatre dvd recorder capossela tab eniac de gregori mix santa marina salina coppia grassoni whirlpool piano cottura laterite canon obiettivo efs lelisir damore dietikon nepal seconda guerra gps bluetooth 20 canali cam chatt marco tumulo xion sito fotografici cartina stradali veneto bigiotteria in vetro extender usb vga european concert 1996 mix twist free download mp3 tu nella mia vita dopo la prova incontro finale ligure d pad heimat 3 sbs vivid 60 silver kuma ya eos 10 amd athlon64 x2 4400 primarete it wollstonecraft mary with this ring tva antonella clerici e la prova del cuoco www latin chat com taglio capelli moda hs 37w toner per sharp fo 4700 renault clio 1 2 16v john wayne incontri benevento vendita online dvd vergini faretto incasso lopez jennifer nuda logitech psp raf ouch copertina cd givani allevamenti ittici sesso cane testo di this love maroon 5 hawksley workman live in lille gipo farassino profumi angel sigma obiettivo 2870mm f 2 8 dg ex v200 1gb creative londonderry la lampada di wood tchien asics onitsuka tiger vivica festa laurea dimagrire mangiando corsa 3 il parto dele nuvole pesanti asus scheda madre socket 775 siamo donne la ragazza che ho lasciato lainate gi no paoli processore amd 64 3000 samurai shodown 3 mhp decoder digitale terrestre htup30 home theatre tuscany accommodation buonsenso sony cyber dsc w12 televisore colori portatile profumi dali scamarcio laghetto inquinato cuore in me hillery orlando albergo radio cd mp3 portatile rina vanna calendario di mascia marzia di maio d m 30 07 01 terzo secolo veriton 7700gx www libero porno com dona room dissipatori a liquido marche di gioielli r e m living in new york firewire scheda pci tragedie ghetto televisore saba ma cosa vuoi che sia una canzone vasco tessile arredamento abruzzo siti pornografici ard abbonamento rai it extended play ristoranti campania i riccordi del cuore radio fm hpr20 san salvator moonlight vs azoto epson quad pack durabrite wellbutrin zanaflex online zyban online fioricet online cheap propecia free mtv ringtones lisinopril online cheap paxil kyocera ringtones ultram mono ringtones didrex online hydrocodone online lorazepam free polyphonic ringtones verizon ringtones free nextel ringtones ambien online music ringtones free nokia ringtones free sonyericsson ringtones pharmacy online online free free ringtones vicodin online cheap diazepam alprazolam cheap ultracet cheap meridia flexeril online lortab online norco online hoodia online sagem ringtones nexium online cheap soma cyclobenzaprine zoloft online jazz ringtones cingular ringtones free motorola ringtones midi ringtones carisoprodol online hgh free sony ringtones tramadol online phentermine online cheap albuterol cheap vigrx free qwest ringtones cheap diethylpropion free sprint ringtones free cool ringtones clomid adipex online levitra online cheap xenical sildenafil online punk ringtones mp3 ringtones xanax online ativan online prozac celexa online cheap ortho tenuate online samsung ringtones lipitor ericsson ringtones free sharp ringtones alltel ringtones valium online free tracfone ringtones sony ericsson ringtones rivotril clonazepam online free real ringtones cialis online viagra online funny ringtones free wwe ringtones == HelloMidletCanvas ==

To get you started and make sure that your environment is working nicely - I've created a fully featured MIDlet which has but one purpose in life - to say hello. The Hello world program has a long and distinguished pedigree in the world of programming and for us it will serve two main purposes:

  1. Verify configuration. Creating and running this simple program lets us know that we've installed the basic software and setup our environment correctly.
  2. Sanity check. I know how it is, you've been up for three days solidly working on your gestural controller / MySpace worm / life size matchstick version of Yoda. You've written this code which looks bug free, but nothing's working. Start at the beginning with the Hello World skeleton application to check your environment and slowly build up your application again.
  • This article assumes you're using Eclipse EclipseME to run this example. Steps may be slightly different for other devices.

Creating a project

  • Right click anywhere in the blank space of the Package Explorer tab in Eclipse. Select New -> Project from the context menu. Select J2ME->J2ME Midlet Suite as the type of project.
  • Name your project something suitable - like HelloMidletCanvas, then click Next.
  • Choose your Device from the list. Anything will do, but if you have something exotic and you're feeling experimental - give it a go. Click Next again and then Finish.

Creating the class

  • Once your project has been created, right-click on the src folder and choose New->Class.</a>
  • Name your class HelloMidletCanvas or whatever you called your project, ensuring that you spell it exactly as you did earlier (including case). Ignore Eclipse if it tries to warn you against using the default package.
  • Once you've done that, copy and paste the text below into your file, overwriting anything that was there before (if you changed names, Eclipse may complain and ask you to update the name of the class). Save the file.
/**
 * HelloMidletCanvas
 * A simple program which demonstrates displaying a string in a Canvas. 
 * 
 * copyleft Michael Sharon 2006
 */

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class HelloMidletCanvas extends MIDlet implements CommandListener {

	//variable to hold a reference to the display
	private Display myDisplay;

	//our exit command
	private Command exit;

	//the canvas we will be painting to
	private Canvas aCanvas;

	public HelloMidletCanvas() {

		//get a reference to the current Display object
		myDisplay = Display.getDisplay(this);

		//create the exit command
		exit = new Command("Exit", Command.EXIT, 1);

		//create a new canvas
		aCanvas = new MyCanvas("Mmmm... canvases.");

		//add the exit command
		aCanvas.addCommand(exit);

		//set a listener for the command
		aCanvas.setCommandListener(this);
	}

	public void startApp() {
		myDisplay.setCurrent(aCanvas);
	}

	public void pauseApp() {
	}

1000

	public void destroyApp(boolean unconditional) {
	}

	public void commandAction(Command c, Displayable s) {
		if (c == exit) {
			destroyApp(false);
			notifyDestroyed();
		}
	}

	//The MyCanvas class takes care of painting the screen
	private class MyCanvas extends Canvas {
		private String message;

		public MyCanvas(String msg) {
			message = msg;
		}

		public void paint(Graphics g) {
			int h = getHeight();
			int w = getWidth();

			g.setColor(200, 100, 20);
			g.fillRect(0, 0, w, h);
			g.setColor(255, 255, 255);
			g.drawString(message, h / 2, w / 2, g.TOP | g.HCENTER);
		}

	}
}

Setup the JAD file

  • Double-click the HelloMidletCanvas.jad file in your Package Explorer. It should open up the EclipseME JAD editor.
  • Click on Midlets, then Add. Type HelloMidletCanvas in the Name field, skip the Icon field and head straight to the Class field. A button should appear, allowing you to select your HelloMidletCanvas source file.

Create a launch configration

  • Right-click your project again, choose Run->Run As from the context menu. Double click Wireless Toolkit Emulator to create a new configuration and name it something like Vanilla MIDlet.

The selected project should be HelloMidletCanvas. Click on the Midlet radio button under the Executable option and then click Search. It should easily find your default HelloMidletCanvas

  • Click Apply, then Run.

Troubleshooting

  • Whoa! Something exploded! Not cool. If you see something like this - that's fine, it just means that we forgot to compile our source file into a JAR file.
  • Right-click your project folder again and choose J2ME -> Create Package

Success!

  • Click the big Green Run button again. This time it should show signs of life and boot up your first Java program in whichever emulator you selected.