U E D R , A S I H C RSS

Mobile Java Study/Hello World

소개

핸드폰에서 'Hello World' 출력.

재동이의 소스

~cpp 
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class HelloWorld extends MIDlet implements CommandListener {
	private Display display;
	private TextBox mainScreen = null;
	private Command exit;
	
	public HelloWorld() {
		display = Display.getDisplay(this);
		mainScreen = new TextBox("HelloWorld","Hello World",512,0);
		exit = new Command("exit", Command.EXIT,2);
		mainScreen.addCommand(exit);
		mainScreen.setCommandListener(this);
	}
	public void startApp() {
		display.setCurrent(mainScreen);
	}
	public void pauseApp() {
	}
	
	public void destroyApp(boolean unconditional) {
	}
	
	public void commandAction(Command c,Displayable s) {
		if(c == exit) {
			destroyApp(false);
			notifyDestroyed();
		}
	}
}

상규의 소스

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

class HelloWorldCanvas extends Canvas {
	public void paint(Graphics g) {
		g.setColor(255,255,255);
		g.fillRect(g.getClipX(),g.getClipY(),g.getClipWidth(),g.getClipHeight());
		g.setColor(0,0,0);
		g.drawString("Hello World!", 0, 0, Graphics.TOP|Graphics.LEFT);
	}
};

public class HelloWorld extends MIDlet implements CommandListener {
	private Display display;
	private HelloWorldCanvas canvas;
	private Command exitCommand;

	public HelloWorld() {
		display = Display.getDisplay(this);
		canvas = new HelloWorldCanvas();
		exitCommand = new Command("Exit", Command.EXIT, 1);

		canvas.addCommand(exitCommand);
		canvas.setCommandListener(this);
	}

	public void startApp() {
		display.setCurrent(canvas);
	}

	public void pauseApp() {
	}

	public void destroyApp(boolean unconditional) {
		display = null;
		canvas = null;
		exitCommand = null;
	}

	public void commandAction(Command c, Displayable d) {
		if(c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();
		}
	}
};
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:46
Processing time 0.0119 sec