Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Creating a field to display web content

Code sample: Displaying HTML content in a browser field

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

//Create the application framework by extending the 
//UiApplication class. In main(), create an instance of 
//the new class and invoke enterEventDispatcher() to enable 
//the application to receive events. In the application 
//constructor, invoke pushScreen() to display the 
//custom screen for the application. 
public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }
    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

//Create the custom screen by extending the MainScreen class.
class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {

//In the screen constructor, create an instance of the BrowserField class.
        BrowserField myBrowserField = new BrowserField();

//In the screen constructor, invoke add() to add the 
//BrowserField object to the screen.
        add(myBrowserField);

//In the screen constructor, invoke BrowserField.displayContent() to 
//specify and display the HTML content.
        myBrowserField.displayContent(
          "<html><body><h1>Hello World!</h1></body></html>", "http://localhost");
    }
}

Code sample: Displaying HTML content from a web page in a browser field

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

//Create the application framework by extending the 
//UiApplication class. In main(), create an instance of 
//the new class and invoke enterEventDispatcher() to 
//enable the application to receive events. In the 
//application constructor, invoke pushScreen() to display 
//the custom screen for the application.
public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }
    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

//Create the framework for the custom screen by extending the 
//MainScreen class.
class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {

//In the screen constructor, create an instance of the 
//BrowserField class.
        BrowserField myBrowserField = new BrowserField();

//In the screen constructor, invoke add() to add the 
//BrowserField object to the screen.
        add(myBrowserField);

//In the screen constructor, invoke BrowserField.requestContent() 
//to specify the location of the HTML content and display it.
        myBrowserField.requestContent("http://www.blackberry.com");
    }
}

Code sample: Displaying HTML content from a resource in your application

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

//Create the application framework by extending the 
//UiApplication class. In main(), create an instance of 
//the new class and invoke enterEventDispatcher() to enable 
//the application to receive events. In the application 
//constructor, invoke pushScreen() to display the custom 
//screen for the application. 
public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }
    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

// Create the custom screen by extending the MainScreen class.
class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {

//In the screen constructor, create an instance of the BrowserField class.
        BrowserField myBrowserField = new BrowserField();

//In the screen constructor, invoke add() to add the 
//BrowserField object to the screen.
        add(myBrowserField);

//In the screen constructor, invoke BrowserField.requestContent() to 
//specify the location of the resource in your application and 
//display the HTML content. The BrowserField class does not access 
//resources using a folder structure. The BrowserField class displays 
//the first resource found that matches the specifed file name.
        myBrowserField.requestContent("local:///test.html");
    }
}

Code sample: Configuring a browser field

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

//Create the application framework by extending the 
//UiApplication class. In main(), create an instance of the 
//new class and invoke enterEventDispatcher() to enable the 
//application to receive events. In the application constructor, invoke 
//pushScreen() to display the custom screen for the application. 
public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }
    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

//Create the framework for the custom screen by extending MainScreen.
class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {

//In the screen constructor, create an instance of BrowserFieldConfig.
        BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();

//In the screen constructor, invoke BrowserFieldConfig.setProperty() to 
//specify  a property of the BrowserField. The first parameter in 
//setProperty()specifies the property, and the second parameter specifies 
//the value of the property. For example, the following code sample 
//specifies the NAVIGATION_MODE property of a BrowserField object:
        myBrowserFieldConfig.setProperty(
              BrowserFieldConfig.NAVIGATION_MODE,
              BrowserFieldConfig.NAVIGATION_MODE_POINTER);

//In the screen constructor, create an instance of the 
//BrowserField class that uses the configuration that you defined.
        BrowserField browserField = new BrowserField(myBrowserFieldConfig);
    }
}

Code sample: Sending form data to a web address in a browser field

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.io.http.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import java.lang.*;
import java.util.*;

//Create the application framework by extending the 
//UiApplication class. In main(), create an instance of 
//the new class and invoke enterEventDispatcher() to 
//enable the application to receive events. In the 
//application constructor, invoke pushScreen() to display the 
//custom screen for the application. 
public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }
    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

//Create the custom screen by extending the MainScreen class.
class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {

//In the screen constructor, create an instance of BrowserField class.
        BrowserField browserField = new BrowserField();}

//In the screen constructor, invoke add() to add the 
//BrowserField object to the screen.
        add(browserField);

//In the screen constructor, create a String object that 
//contains the base web address of the web page that 
//you are sending the form data to.
        String baseURL = "http://www.blackberry.com";

//In the screen constructor, create a String that specifies the 
//form data that your application sends to the web page.
        String postData = "fieldname1=value1&fieldname2=value2";

//In the screen constructor, create a Hashtable object to store the 
//header information for the form data.
        Hashtable header = new Hashtable();

//In the screen constructor, invoke Hashtable.put() to specify the 
//header information for the form data.
        header.put("Content-Length", "" + postData.length());
        header.put("Content-Type", "application/x-www-form-urlencoded");

//In the screen constructor, invoke BrowserField.requestContent() to 
//send the form data to the web page and display the web page.
        browserField.requestContent(
                                    baseURL, 
                                    postData.getBytes(), 
                                    new HttpHeaders(header));
    }
}