3
我正在研究一個簡單的J2ME應用程序,並且我有一個鏈接到條款和條件頁面的StringItem。無法在J2ME中打開網站鏈接
我有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());
}
}
}
我怎樣才能解決這個問題,這樣,當我點擊的條款和條件鏈接,它打開的頁面上的瀏覽器?