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
Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel
Accepted Solution

Not able to make a call to custom class

Hi All,

I am trying to call the custom class from the main screen as below ,but its not picking up the features of the custom class and giving the output ,i am not sure if something is wrong in the below class or the way i am calling this method.

 

package com.ge.bbcalendar;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;

public class TestClass extends LabelField {
    private boolean focussed;
    private String text;
    private long style;

    public TestClass(String text, long style) {

        super();
        this.text = text;
        this.style = style;
    }

    protected void onFocus(int direction) {
        focussed = true;
        invalidate();
        super.onFocus(direction);

    }

    protected void onUnfocus() {
        focussed = false;
        invalidate();
        super.onUnfocus();
    }

    protected void paint(Graphics graphics) {
        graphics.setColor(Color.WHITE);
        graphics.setBackgroundColor(0x544E4F);
        if (focussed) {
            graphics.setColor(Color.BLUE);
        }
        graphics.clear();
        super.paint(graphics);
    }
}


 

Called like from mainscreen

public class NativeScreen extends MainScreen {

 

    final TestClass time15 = new TestClass("",LabelField.FOCUSABLE) ;
}

 

What is wrong above ?

 

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Not able to make a call to custom class

My initial guess is this:

 

        graphics.clear();
        super.paint(graphics);

 

Why do you call clear() before the call to paint()?

 

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

Re: Not able to make a call to custom class

[ Edited ]

I take it the thing you are missing is the background color not being correct.

 

If so, remember that clear uses the BackgroundColor, so you need to set it.  I would rework your paint method as follows:

 

        graphics.setBackgroundColor(0x544E4F);
        if (focussed) {
            graphics.setBackgroundColor(Color.BLUE);
        }
        graphics.clear();
        graphics.setColor(Color.WHITE);

        super.paint(graphics);

 

If this is not your problem, can you explain what you are missing when you use this class?

 

Have you used the debugger to see if you are going through the code in this class?

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Not able to make a call to custom class

Another thing:

 

Your constructor gets two parameters: style & text, but both parameters are not used.

 

Try using:

super(text, style);

 

E.

Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Re: Not able to make a call to custom class

I have debugged the class and using the same paint method edited by you ,and the constructor i have changed to
public TestLabel(String text, long style) {
super("",FOCUSABLE);
text = text;
style = style;
}

I am nt getting the focus method output defined in the class ,certainly it goes to the focus method and sets the color ,but i cannot see on the screen
Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Not able to make a call to custom class

Can you please explain in words how the field should be displayed, with and without the focus?

Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Re: Not able to make a call to custom class

[ Edited ]

I have created the custom class to get a focus on labelfield ,which has black background and white text so i was doing
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
graphics.setBackgroundColor(0x544E4F);
if (focussed) {
graphics.setColor(Color.BLUE);
}
graphics.clear();
super.paint(graphics);
}

and wanted to set the focus color as blue,but it not working out.

If i add the same piece of code in the mainscreen instead of custom class it works .The label field value is 7 :00 just want to hightlight this text on select .

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Not able to make a call to custom class

If you want just to change the colors when the field has focus, you can just override the drawFocus method:

http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/Field.html#drawFocus%28net....

 

If you wish to change the basic loop & feel of the field, then you should override the paint method.

 

BTW, in your case, I would have considered overriding the method anonymously:

 

LabelField lf = new LabelField(myText, myStyle){

  protected void drawFocus(...){

  // put your code here

  }

}

 

E.

Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Re: Not able to make a call to custom class

Ya right i can also use this method ,but these method should get called in my custom class,the paint method itself is not getting called then the same behavior with this.I have n number of labelfields so wanted to have this logic in custom
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Not able to make a call to custom class

I suspect your problem is that the LabelField doesn't think it has any text to display.

 

You really need this I think

 

public TestLabel(String text, long style) {
super(text,FOCUSABLE);

...