买的七喜M73居然不支持Java,想看看电子书也没有办法。最近鼓捣Sun的WTK,发现有的例子居然能运行,立刻有了兴趣,折腾一阵,弄出一个perl的脚本,可以生成相关的Java源文件,然后在WTK里编译生成jar文件,虽然麻烦,不过总算可以看了。
不过复杂一些的例子就不能运行了,也不知道为什么,是手机支持的API版本太低还是干脆就屏蔽了,不得而知。
#!/usr/bin/perl
if($#ARGV != 1) {
print("Usage: $0 txtfile javafile/n");
exit(0);
}
my $txtfile = $ARGV[0];
my $javafile = $ARGV[1];
print "Open file $txtfile .../n";
open FH, $txtfile or die "open file $txtfile failed/n";
my @txt = <FH>;
close FH;
open FH, ">$javafile" or die "open file $javafile failed/n";
print FH <<EOF;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class TinyMIDlet
extends MIDlet
implements CommandListener {
public void startApp() {
Display display = Display.getDisplay(this);
Form mainForm = new Form("TinyMIDlet");
EOF
foreach my $line(@txt) {
chomp($line);
#print "-- $_/n";
print FH " mainForm.append(/"", $line, "/");/n";
}
print FH <<EOF2;
Command exitCommand = new Command("Exit", Command.EXIT, 0);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
display.setCurrent(mainForm);
}
public void pauseApp () {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
}
}
EOF2
close FH;