java me手机版,JAVA ME 手机程序入门级源码

一个由 Carol Hamer 写的比较有代表性的源码,作者全力推荐,尤其是对于没有 J2ME 开发经验的朋友。自己动手敲出以下贴出的 Hello.java 和 HelloCanvas.java 源码,并运行,用心体会一下。相信你理解了此源码之后,即可步入 J2ME 开发。

注释都在源码里,运行环境自己配,自己动手看运行效果,理解之后,然后动手修改一下源码,J2ME 开发,你可以的!

Hello.java 源码:

package net.frog_parrot.hello;

import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;

/**

* This is the main class of the hello world demo

*

* @author Carol Hamer

*

*/

public class Hello extends MIDlet implements CommandListener {

/**

* The canvas is the region of the screen that has bean alloted to the game

*/

HelloCanvas myCanvas;

/**

* The Command objects apears as buttons.

*/

private Command exitCommand = new Command("Exit",Command.EXIT,99);

/**

* The Command objects apears as buttons.

*/

private Command newCommand = new Command("Toggle Msg",Command.SCREEN,1);

/**

* initialize the canvas and the commands

*/

public Hello() {

myCanvas = new HelloCanvas(Display.getDisplay(this));

myCanvas.addCommand(exitCommand);

myCanvas.addCommand(newCommand);

myCanvas.setCommandListener(this);

}

//--------------------------------

// implementation of MIDlet

/**

* Start the application

*/

protected void startApp() throws MIDletStateChangeException {

myCanvas.start();

}

/**

* This method is called to notify the MIDlet to enter a paused state.

* The MIDlet should use this opportunity to release shared resources.

*/

protected void pauseApp() {

}

/**

* If the MIDlet was using resources,it should release them in this method

*/

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

//-----------------------

// implementation of CommandListener.

/**

* Respond to a command issued on the Canvas

* (either reset or exit)

*/

public void commandAction(Co

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值