开发者

How to create an URL in Blackberry program

开发者 https://www.devze.com 2023-01-11 01:45 出处:网络
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.

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

精彩评论

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