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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Contributor
mrdialect2012
Posts: 27
Registered: ‎05-10-2012
My Carrier: Vodafone

How do i add an image to my screen, simple question

I am extending full screen on my class and would like to add an image to the screen.

 

So far I have looked online for help in doing so and have wrote this thus far. Not sure why my image isnt displaying.

 

 

package mypackage;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class IntroPage extends FullScreen{

	Bitmap backgroundBitmap = Bitmap.getBitmapResource("background.png");

	public IntroPage()
	{
       ButtonField buttonField_3 = new ButtonField( "Start", ButtonField.CONSUME_CLICK | ButtonField.FIELD_VCENTER  );
		
		final selectionPage i = new selectionPage();
		
		buttonField_3.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                UiApplication.getApplication();
				synchronized (Application.getEventLock()) {
                    UiApplication.getUiApplication().pushScreen(i);
                }
            }
        });
	add( buttonField_3 );
	
	}
	
	
	HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH |
	HorizontalFieldManager.USE_ALL_HEIGHT){
	
		protected void paint(Graphics g) {
		
		g.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundBitmap, 0, 0);
		
		super.paint(g);
		
		//g.drawText("Tic Tac Toe", 280, 170);
	
	}
	};
	
}

 

Please use plain text.
Developer
peter_strange
Posts: 17,698
Registered: ‎07-14-2008

Re: How do I add an image to my screen, simple question

You seem to be tying to display your image as the background to a HorizontalFieldmanager.  I am not sure about your use of USE_ALL_HEIGHT and USE_ALL_WIDTH for this, nor am I sure about what will happen when you try to paint the Bitmap across the entire width and height (what if it is not the right size?).  But the biggest problem I see is that you never add this manager to the screen.

 

I recommend that you review this: 

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

 

I know you are trying to extend FullScreen, but a MainScreen is really a FullScreen with extra function, so I think the basics explained are also applicable (look at the comments too BTW).

 

I would also review this KB article:

http://supportforums.blackberry.com/t5/Java-Development/Use-a-background-image-in-application-screen...

 

You will find other useful stuff if you search here for background image.

Please use plain text.