自动生成java电子书的perl程序

买的七喜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;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值