Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 5
Registered: ‎09-01-2009
My Device: Storm 9500
Accepted Solution

Launching Browser from Java button click

Hi Guys, 

 

first time poster, hoping you guys can give me a steer. I'm a novice at coding and am worried I've bitten off more than I can chew!!!

 

I have the following code snippet from a program i'm putting together, and the object is that when the user clicks on the fullscreen button "fullScreenC1111", the app will launch a web page. I'm not very good with handlers and that sort of thing, so if anyone could please take a look at my code and let me know how to add in the functionality, I'd be really grateful. if this has been done else where i apologise for the double post....

 

 

class Cineberry extends net.rim.device.api.ui.UiApplication 
{
    public static void main(String[] args)
    {
        Cineberry instance = new Cineberry();
        instance.enterEventDispatcher();
    }  
    public Cineberry() 
    {
        pushScreen(new CountyList11());
    }
}


import net.rim.device.api.ui.*;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.Manager.*;
import net.rim.blackberry.api.browser.Browser;
import java.util.*;


public class CountyList11 extends MainScreen
{
    
        ButtonField btnCl111;
        ButtonField btnCl112;
        CustomButtonField fullscreenCl111;
        
       
        
  public CountyList11()
    {
     
         
        super();
             
        Bitmap HELLO_LOGO = Bitmap.getBitmapResource("cineberry.png");
        BitmapField helloBmpField = new BitmapField(HELLO_LOGO);   
        add(helloBmpField);  
             
        LabelField applicationTitle = new LabelField("Cineberry Location List");
        setTitle(applicationTitle);
        
        add(new SeparatorField());
        
        RichTextField cineberryTextField = new RichTextField("Please Choose a County");
        add(cineberryTextField);
        
        add(new SeparatorField());
        
        
        
        add(new RichTextField(Field.NON_FOCUSABLE));
        fullscreenCl111 =  new CustomButtonField("Omniplex Carlow", CustomButtonField.FULLSCREEN, Field.FOCUSABLE);
        
        fullscreenCl111.browserSession.displayPage("http://www.google.ie/movies?hl=en&near=carlow&dq=omniplex+carlow&theater=omniplex&ei=OMHYS5GIBIj00gS...");
        add(fullscreenCl111);
                   
        
        
                   
        add(new SeparatorField());        
        
        btnCl111 = new ButtonField("Back To A - Z", ButtonField.CONSUME_CLICK | EditField.FIELD_HCENTER);
        btnCl111.setChangeListener(new ButtonListener2());
        add(btnCl111);
        
        btnCl112 = new ButtonField("Back To Home Screen", ButtonField.CONSUME_CLICK | EditField.FIELD_HCENTER);
        btnCl112.setChangeListener(new ButtonListener1());
        add(btnCl112);
        

  
    }
    

}

 

 

I know i've probably imported too many packages as well, but I can figure that out at a later stage.

 

thanks in advance

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Launching Browser from Java button click

You want to invokde the browser from your button listener(s)

 

I would drop down to a single listener and look at the field passed in to determine which button was clicked.

 

Here is an article on invoking the browser.

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800440/How_To_...

 

Please bookmark the knowledgebase while you are in there.

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Launching Browser from Java button click

[ Edited ]

Welcome,

 

Just created a code sample, and noted RexDoug's post.  This mainly replicates it, but I 'd started so perhaps it might be useful....

 

public class TestScreen extends MainScreen 
                        implements FieldChangeListener {

    ButtonField _backButton = null;
    ButtonField _homeButton = null;
    ButtonField _cinemaButton = null;

    public TestScreen() {
        setTitle("Test Button Processing");

        _cinemaButton = new ButtonField(("Omniplex Carlow", ButtonField.CONSUME_CLICK | EditField.FIELD_HCENTER);
        _cinemaButton.setChangeListener(this);
        add(_cinemaButton);

        _backButton  = new ButtonField("Back To A - Z", ButtonField.CONSUME_CLICK | EditField.FIELD_HCENTER);
        _backButton.setChangeListener(this);
        add(_backButton);

        _homeButton = new ButtonField("Back To Home Screen", ButtonField.CONSUME_CLICK | EditField.FIELD_HCENTER);
        _homeButton.setChangeListener(this);
        add(_homeButton);

    }

    public void fieldChanged(Field field, int context) {
        if ( field == _cinemaButton ) {
            // Code based on DB-00701, KB article referenced by RexDoug
        }
        if ( field == _backButton ) {
            // whatever the back button should do
        }
        if ( field == _homeButton ) {
            // whatever the home button should do
        }
    }

    public void close() {
        UiApplication.getUiApplication().popScreen(this);
    }

}

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Launching Browser from Java button click

...and here is a simple way to invoke the browser on the newer OS levels:

 

        BrowserSession browser = Browser.getDefaultSession();
        browser.displayPage("www.google.com");       

 

New Contributor
Posts: 5
Registered: ‎09-01-2009
My Device: Storm 9500

Re: Launching Browser from Java button click

Hi Guys,

 

thanks for the replies, I'll give these a go when i get home tonight.

New Contributor
Posts: 5
Registered: ‎09-01-2009
My Device: Storm 9500

Re: Launching Browser from Java button click

RexDoug and Peter Strange, i hereby pronounce you joint kings of the world....

 

that's worked for me. thanks a million

Contributor
Posts: 42
Registered: ‎10-23-2011
My Device: curve 8520
My Carrier: george najem

Re: Launching Browser from Java button click

Hello sir,

 

i was wondering, would u mind please sharing your entire solved code as i am experiencing the same problem

 

kind regards

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Launching Browser from Java button click

Probably better to start your own post, rather than add to a solved thread.

 

It is hard to see what code you are missing, since there is code here to handle buttons and to invoke the Browser.  What problem are you actually having?