Saturday, February 6, 2010

Blackberry Version Program: show a picture on the screen

// 1. HelloWorldScreen.java

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;

public class HelloWorldScreen extends MainScreen {

    private static final Bitmap myBitmap = Bitmap.getBitmapResource("example2.png");

    public HelloWorldScreen() {        
        try
        {
            BitmapField bitmapField = new BitmapField(myBitmap);
            add(bitmapField);            
        }
        catch(Exception e)
        {
            int i;            
            i = 100;
        }
    }
}


// 2. helloworld.java

import java.io.OutputStreamWriter;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import net.rim.device.api.ui.UiApplication;



public class helloworld extends UiApplication {

    public helloworld() {
        HelloWorldScreen screen  = new HelloWorldScreen();
        pushScreen(screen);
    }
}


Note: File example2.png should put under the same directory as the src java files. Otherwise, not able to show the pic.

No comments: