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
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

public class Abcd extends UiApplication { public static void main(String[] args) { new Abcd().enterEventDispatcher(); } Abcd() { pushScreen(new B()); } class B extends MainScreen { A a; B() { setTitle("ABCD"); VerticalFieldManager vfm = new VerticalFieldManager(); a = new A(); vfm.add(a); vfm.add(new C()); this.add(vfm); } } class A extends Manager implements FieldChangeListener { int xStart, yStart; int xInter, yInter; int xDest, yDest; ButtonField btn; Bitmap img = Bitmap.getBitmapResource("img/moustique2.png"); A() { super(Manager.HORIZONTAL_SCROLL); xStart = 100; yStart = 150; xDest = 200; yDest = 200; xInter = 25; yInter = 25; btn = new ButtonField("A"); add(btn); btn.setChangeListener(this); updateLayout(); } protected void sublayout(int width, int height) { setPositionChild(btn, xStart, yStart); layoutChild(btn, btn.getWidth(), btn.getHeight()); setExtent(300, 150); } protected void paint(Graphics graphics) { graphics.setBackgroundColor(Color.CYAN); graphics.drawBitmap(xStart, yStart, img.getWidth(), img.getHeight(), img, 0, 0); } protected void getCordinates() { xStart += xInter; yStart += yInter; } public void fieldChanged(Field field, int context) { add(new C()); updateLayout(); } } class C extends Manager { C() { super(Manager.HORIZONTAL_SCROLL); add(new ButtonField("C")); } protected void sublayout(int width, int height) { setExtent(300, 150); } public void paint(Graphics g) { g.setBackgroundColor(Color.RED); } } }

 


Hi all,

         i didnt find whats wrong with this code. am just getting a blank white screen with title as ABCD. how to add fields and images at a time. my code is not working just giving a white screen. please suggest me how to fix this.

 

 

 

Thanks and Regards,

PraveenGoparaju.
Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

Having a quick look at your code I think the problem is in your sublayout() and paint() method.

Try somthing like this:

 

protected void sublayout(int width, int height)
{
setPositionChild(btn, xStart, 0/*have to less than 150*/);
layoutChild(btn, width, height);
setExtent(300, 150);
}
protected void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.CYAN);
graphics.clear();
graphics.drawBitmap(xStart, yStart, img.getWidth(),
img.getHeight(), img, 0, 0);
super.paint(graphics);
}

 

Have a look at the KB article about writing your own manager.

 

How to - Create a custom layout manager for a screen

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

 

Regards

Bikas

 

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

class A extends VerticalFieldManager implements FieldChangeListener { LabelField bestScore, gameScore; ButtonField btn_OK; A(String score) { bestScore = new LabelField(score); gameScore = new LabelField(score); Background back = BackgroundFactory.createSolidTransparentBackground(Color.PINK, 0); this.setBackground(back); btn_OK = new ButtonField("OK", Field.FOCUSABLE); add(btn_OK); btn_OK.setChangeListener(this); } public void fieldChanged(Field field, int i) { UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); } protected void sublayout(int width, int height) { if( btn_OK != null) { setPositionChild(btn_OK, 80, 125); layoutChild(btn_OK, 250, 200); } setExtent( 300, 200); } protected void paint(Graphics g) { //g.setBackgroundColor(Color.PINK); g.clear(); g.setColor(Color.BLUEVIOLET); g.drawText("Score Board", 80, 30); g.setColor(Color.SPRINGGREEN); g.drawText("BestScore : "+bestScore.toString(), 50, 75); g.drawText("YourScore : "+gameScore.toString(), 50, 105); } }

 

        Hi Bikas,

                       thanks for your quick reply. then what is wrong with this code???? the button is not visible in the popupscreen but it is catching the click event. now am not getting a blank screen instead it is populated with the paint method data. eventhough the btn_OK is not visible it is listening to the click event and the popupscreen is closed when i click at the location. 

 

              also please suggest me how make my popupscreen completely transparent. am not getting a screen with thick black border how can i remove that black border and view only the popupscreen without the border.

 

 

Thanks and Regards,

PraveenG 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

Add the following at the end of your paint() method.

 

super.paint(g);

 

Regards

Bikas

 

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

Thank you Bikas,

 

                  once again thanks for your quick reply. it works and now the btn_OK is visible. but i didnt know the reason  to call paint() to add fields to a manager.

                if you find time please suggest me how to get a transparent popupscreen? am extending the PopupScreen class to myClass. the screen is popping but with a thick black border. i used the setBackground to make it transparent. but the problem is the thick black border is not removing. i need to remove that black border

 

Thanks and Regards,

Praveen.G 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.