求J2me程序代码。
这个程序很难吗?还是怎么回事? 展开
很明确的告诉楼主,这个问题很简单,半专业的程序员、业余J2me爱好者会在1个小时内给出代码。代码一小时内出来……
终于出来了,运行正常,手机顽童模拟器测试正常。真机待测(因为我的手机不支持java),如果想要打好的包,请留下邮箱,我讲发给你。废话不多说了,直接贴代码:
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class MyMidlet extends MIDlet implements CommandListener{
private Display dis;
private Command reput,exit,fin;
private Form form;
private TextField tf,tim;
private StringItem si,input,resu;
private String put;
private Alert al;
private int v,time;
private Image img;
private Spacer sp,sp2;
public MyMidlet() {
put="";
try {
img=Image.createImage("/j2me.PNG");
} catch (IOException e) {
e.printStackTrace();
}
dis=Display.getDisplay(this);
reput=new Command("重新输入",Command.OK,2);
exit=new Command("退出",Command.EXIT,2);
fin=new Command("计算",Command.BACK,2);
form=new Form("J2ME距离计算器");
tf=new TextField("速度","",10,TextField.NUMERIC);
tim=new TextField("时间","",10,TextField.NUMERIC);
si=new StringItem("说明","输入速度和时间,按计算确认");
al=new Alert("错误操作!");
al.setTitle("J2ME系统警告");
input=new StringItem("输入的数据:",put);
resu=new StringItem("计算结果:","");
sp=new Spacer(form.getWidth(),10);
sp2=new Spacer(form.getWidth()/2-img.getWidth()/2,img.getHeight());
form.append(si);
form.append(tf);
form.append(tim);
form.append(input);
form.append(resu);
form.append(sp);
form.append(sp2);
form.append(img);
form.addCommand(reput);
form.addCommand(fin);
form.addCommand(exit);
form.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
dis.setCurrent(form);
}
public void commandAction(Command c, Displayable d) {
if(c==fin){
if(tf.getString().length()>0&&tim.getString().length()>0){
v=Integer.parseInt(tf.getString());
time=Integer.parseInt(tim.getString());
input.setText(tf.getString()+"*"+tim.getString());
resu.setText(tf.getString()+"*"+tim.getString()+"="+new Integer(v*time));
}else{
al.setString("请输入速度和时间");
dis.setCurrent(al, form);
}
}else if(c==exit){
try {
destroyApp(false);
notifyDestroyed();
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
}else if(c==reput){
tf.setString("");
tim.setString("");
input.setText("");
resu.setText("");
}
}
}
怎么样,简单吧?
为了见效果,老样子:先睹为快!
2024-09-19 广告