BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-31-2007, 07:27 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: vodafone
Posts: 37
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble with Paint/Repaint() Midlet

Please Login to Remove!

Hi,

I'm porting a Midlet accross to BlackBerry, and I have managed to implement the TrackwheelListener to my application to ensure normal standard blackberry navigation.

However, when the application loads, initially, it paints all the images. Immediately, however, it repaints the screen with only the object with focus being redrawn.

I'm aware that there can be issues from marrying together the UIApplication and Midlet code, however, I have only added TrackwheelListener to my Midlet code.

Any advice/knowledge is most welcome!

regards,

Tig*
Offline  
Old 10-31-2007, 10:28 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

this could be a few things, a code sample could help us figure out which it is.
Offline  
Old 11-01-2007, 06:07 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: vodafone
Posts: 37
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

O.k. My Main class extends midlet, and looks something like this:

Code:
public class SMain extends MIDlet {
    
    private final MFrame frame = SConstants.FRAME;
    public final static int ID_MAIN         = 0; 
    ....
    
    public static MDataBean currBean=null;
    
    protected void startApp() throws MIDletStateChangeException {
    	if (frame == null || Display.getDisplay(this).getCurrent() == null) {
		init() ;
	}else {
		frame.getCurrentPanel().doFullRepaint = true;
		frame.getCurrentPanel().repaint() ;
	}
}

public void init(){
						
	AppEnvironment env = SConstants.EN;
	SFactoryListPanel  mainMenu = new SFactoryListPanel("Main Menu",SConstants.SIMPLE_LIST, false,true);
	   
        mainMenu.addCommand(SConstants.exitCommand);
        mainMenu.addCommand(SConstants.selectCommand);
        ....

	frame.addPanel(mainMenu, ID_MAIN);
	....

	SPanelMediator mediator = new SPanelMediator(this, frame);
        // MFrame_BlackBerry extends Canvas.
	Display.getDisplay(this).setCurrent((MFrame_BlackBerry)frame);
        ....

}
MFrame_BlackBerry extends Canvas, and acts like this:

Code:
public class MFrame_BlackBerry extends Canvas implements MFrame, TrackwheelListener{
    
    protected Hashtable panels;
    protected MPanel currentPanel;
    protected int currentPanelID = -1;
    
    private Command[] myCommands = new Command[2];
    
    /** Creates a new instance of MFrame */
    public MFrame_BlackBerry(){
    	Application.getApplication().addTrackwheelListener(this);
    	MPanel.setDimensions(getWidth(), getHeight(), 0);
    	
        panels = new Hashtable();
        setCommandListener(this);
    }

    ....
    
    public void paint(Graphics g){
        if(currentPanel == null) return ;
        
        currentPanel.paintPanel(g);
        
    }
}
Now the currentPanel is of type MPanel, and its paintPanel(g) method is described below:

Code:
    public void paintPanel(Graphics g){
    	g.setClip(0, 0, getWidth(), getHeight());
    	
    	isShowing           = true;
        if(doFullRepaint){
            paintBackgound(g, 0, 0, getWidth(), getHeight());
            paint(g);
        } else if(components.contains(repaintComponent) && repaintComponent != null){
            paintBackgound(g, repaintComponent.getX(), repaintComponent.getY(),
            repaintComponent.getWidth(), repaintComponent.getHeight());
        }
        int numComp = components.size();
        for(int i = 0; i < numComp; i++){
            MComponent component = (MComponent)components.elementAt(i);
            if((doFullRepaint || repaintComponent == component) && focusComponent != component){
                component.paintComponent(g);
            }
        }
        if (focusComponent != null) {
        	focusComponent.paintComponent(g);
        }
        g.setClip(0, 0, getWidth(), getHeight());
        doFullRepaint = false;
    }
Now its worth noting that the Display is fine on any normal mobile phone, without any of the implemented trackwheellistener stuff, so I suspect the problem lies in the MFrame_BlackBerry paint() method.

Regards,

Tig*
Offline  
Old 11-01-2007, 10:46 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

this could be the culprit:
else if(components.contains(repaintComponent) && repaintComponent != null){
paintBackgound(g, repaintComponent.getX(), repaintComponent.getY(),
repaintComponent.getWidth(), repaintComponent.getHeight());
}


not sure what paintBackround itself does, but if one implements a background paint in standard bb, it does a canvas.clear then does the paint, which is why you might see only the repaintComponent.

that's really just a guess though, I'm not 100%
Offline  
Old 11-01-2007, 12:41 PM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: vodafone
Posts: 37
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
if one implements a background paint in standard bb, it does a canvas.clear then does the paint, which is why you might see only the repaintComponent.
Hi,

Thanks, this was very useful, as I've managed to get it to repaint some of the text, and now, I just have to repaint the components accordingly.

I'll let you know when I've got it complete, but thanks again.

Regards,

Tig*
Offline  
Old 11-02-2007, 05:41 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2007
Model: 8700
PIN: N/A
Carrier: vodafone
Posts: 37
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yea, that worked a treat.

One question though. Any idea why paintBackground clears the canvas? doesnt make much sense to me...

Regards,

Tig*
Offline  
Old 11-02-2007, 10:34 AM   #7 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

just one of life's great mysteries I suppose. glad that it worked for you
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.