我正在开发一个简单的 J2ME 应用程序,并且我有一个链接到在线条款和条件页面的 StringItem。
我有 StringItem 设置,它显示有下划线(给人一种链接的感觉);但是当我单击它时,它不会执行任何操作。
在我的代码下面找到:
public class mobiMidlet extends MIDlet implements CommandListener {
private Display display;
private TextField userName,password;
public Form form;
private Command login, register, forgot, terms, cancel;
private Image img_error, img_login, img_register, img_forgot, img_terms;
private String termsurl = "http://example.com/terms.php";
private StringItem termsItem;
public mobiMidlet() {
form = new Form("Welcome to My App");
termsItem = new StringItem("", "Terms and Conditions", Item.HYPERLINK);
termsItem.setDefaultCommand(new Command("terms", Command.ITEM, 1));
ItemCommandListener listener = new ItemCommandListener() {
public void commandAction(Command cmd, Item item) {
if(cmd==terms)
{
try {
platformRequest(termsurl);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
termsItem.setItemCommandListener(listener);
userName = new TextField("LoginID:", "", 30, TextField.ANY);
password = new TextField("Password:", "", 30, TextField.PASSWORD);
cancel = new Command("Cancel", Command.CANCEL, 2);
login = new Command("Login", Command.OK, 2);
try{
img_login = Image.createImage("/logo.jpg");
img_register = Image.createImage("/error2.png");
img_forgot = Image.createImage("/logo.jpg");
img_register = Image.createImage("/error2.png");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public void startApp() {
display = Display.getDisplay(this);
form.append(termsItem);
form.append(userName);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
}
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if(label.equals("Cancel")) {
destroyApp(true);
} else if(label.equals("Login")) {
validateUser(userName.getString(), password.getString());
}
}
}
我该如何解决这个问题,以便当我点击条款和条件链接时,它会在浏览器上打开页面?