帮看一段简单的程序吧
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class LoginMidlet extends MIDlet implements CommandListerer{
private Display display;
private TextField userName;
private TextField password;
private Form form;
private Command cancel;
private Command login;
public LoginMidlet(){
userName = new TextField( "用户名: ", " ",10,TextField.ANY);
password = new TextField( "密码: ", " ",10,TextField.PASSWORD);
form = new Form( "登录 ");
cancel = new Command( "取消 ",Command.CANCEL,2);
login = new Command( "登录 ",Command.OK,2);
public void startApp(){
display = Display.getDisplay(this);
form.append(userName);
form.append(password);
form.append(cancel);
form.append(login);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void validateUser(String name,String password){
if(name.equals( "admin ") && password.equals( "admin888 ")){
menu();
}else{
tryAgain();
}
}
public void menu(){
List services = new List( "请选择 ",Choice.EXCLUSIVE);
services.append( "验证邮件 ",null);
services.append( "公司 ",null);
services.append( "地址 ",null);
services.append( "选项 ",null);
services.append( "退出 ",null);
display.setCurrent(services);
}
public void tryAgain(){
Alert error = new Alert( "登录错误 ", "请重试 ",null,AlertType.ERROR);
error.setTimeout(Alert.FOREVER);
userName.setString( " ");
password.setString( " ");
display.setCurrent(error,form);
}
public void commandAction(Command c,Displayable d){
String label = c.getLagel();
if(label.eauqls( "取消 ")){
destroyApp(true);
}else if(label.equals( "登录 ")){
validateUser(userName.getString(),password.getString());
}
}
}
}
Project settings saved
Building "LoginMidlet "
C:\Program Files\WTK25\apps\LoginMidlet\src\LoginMidlet.java:16:
非法的表达式开始 public void startApp(){
^
C:\Program Files\WTK25\apps\LoginMidlet\src\LoginMidlet.java:61: 需要 '; '
}
^
2 错误
com.sun.kvem.ktools.ExecutionException
Build failed
------解决方案--------------------无语了,你自己对书好好看看吧,你把方法放到方法里了...
------解决方案--------------------。。。。比我还新人, 哈哈
构造函数里面不能写方法
------解决方案--------------------Command用addCommand()来添加,不能用append