Wednesday 24 October 2012

Creating a HyperLink in j2me

This article will  helps you to display a Hyperlink on (LCDUI User Interface) Form Screen for a WebURL.

If an user clicks on the link it will opens the Hyperlink on  a Phone Default Browser.

You Can find the Complete Code Below:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
/**
 * @author pavan
 */
public class HyperLinkMidlet extends MIDlet {
     String url = "http://www.google.com";
    private Display display;
    private StringItem stringItem;
    private Form form;
     Command com ;
    public HyperLinkMidlet() {
        form = new Form("HyperLink");
                com = new Command("Set", Command.ITEM, 1);
        stringItem = new StringItem("Click Here: ", "Set", Item.HYPERLINK);
    }
    public void startApp() {
        display = Display.getDisplay(this);
         stringItem.setText(url);
        stringItem.setDefaultCommand(com);
        form.append(stringItem);
        display.setCurrent(form);  
        stringItem.setItemCommandListener(new ItemCommandListener() {
            public void commandAction(Command c, Item item) {
                if (c == com) {
                    try {
                        platformRequest(url);
                    } catch (ConnectionNotFoundException ex) {
                    }
                }
            }
        });
 
       }
        public void pauseApp() {
         }
       public void destroyApp(boolean unconditional) {
      }
 
      }

No comments:

Post a Comment