import javax.microedition.lcdui.*;
public class Displayable1 extends TextBox implements CommandListener {
Ticker ticker;
Command myCommand;
public Displayable1() {
super("welcome", "hello world", 150, TextField.ANY);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
myCommand=new Command("Set Text",Command.OK,1);
ticker=new Ticker("hello every one I am wangwei!");
setTicker(ticker);
}
public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if(command==myCommand)
{
ticker.setString(getString());
}
if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
MIDlet1.quitApp();
}
}
}
另外一个定义MIDlet类的程序MIDlet.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MIDlet1 extends MIDlet {
static MIDlet1 instance;
Displayable1 displayable = new Displayable1();
public MIDlet1() {
instance = this;
}
public void startApp() {
Display.getDisplay(this).setCurrent(displayable);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
出现的错误:如下
D:\jbuilder2006\j2mewtk2.2\bin\emulator.exe -classpath "C:\Documents and Settings\WANG\jbproject\ticker\classes;" -Xdevice:MediaControlSkin -Xdescriptor:"C:\Documents and Settings\WANG\jbproject\ticker\jad-temp\ticker.jad"
正在通过存储根 MediaControlSkin 来运行
Unable to create MIDlet ticker.ticker
java.lang.ClassNotFoundException: ticker/ticker
at com.sun.midp.midlet.MIDletState.createMIDlet(+14)
at com.sun.midp.midlet.Selector.run(+22)
Execution completed.
698154 bytecodes executed
21 thread switches
741 classes in the system (including system classes)
3509 dynamic objects allocated (101500 bytes)
1 garbage collections (0 bytes collected)
[此贴子已经被作者于2006-10-19 11:13:40编辑过]