开发者

How to create an URL in Blackberry program

Can anyone tell开发者_开发技巧 me how to create an URL link in Blackberry, which opens a web page after it's been clicked?


// This can eb a nested class in your screen class. 
class URLButtonField extends ButtonField {  
    String url; 
    public URLButtonField(String label, String url) { 
        super(label); 
        this.url = url; 
    } 
    public String getURL() { 
        return url; 
    } 
    public void setURL(String url) { 
        this.url = url; 
    } 
}    



// member variable of your screen class- this will let you access it later 
// to change the URL
URLButtonField bf;

// In your screen's constructor: 

bf = new ButtonField("Example", "http://www.example.com"); 
bf.setFieldChangeListener( new FieldChangeListener() { 
    void fieldChanged(Field field, int context) { 
        if (field == this) { 
            BrowserSession session =- Browser.getDefaultSession();
            session.displayPage(getURL()); 
        }
    } 
} );         
add(bf);

You can then change the text or destination URL of "bf" at any time, and whatever you change it to will be the URL that is launched when it is clicked:

// In response to some activity: 
bf.setText("Example Two"); 
bf.setURL("http://www.example.com/two"); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜