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
Contributor
tusharpandey
Posts: 10
Registered: ‎01-19-2013
My Device: 9900
Accepted Solution

Why we use , pushContext() amd popContext() method in blackberry , because they dont create any effect in screen !

and , why we use pushContext() , if you just want to popit after someline .

 

public class field_extendit extends Field
{
field_extendit ( long style )
{
super( style );
}

protected void layout(int width , int height )
{
setExtent(width, height);
}

protected void paint(Graphics graphics )
{
XYPoint b_r = new XYPoint(200, 200) ;
XYPoint t_l = new XYPoint(20 , 20 );
XYRect rect = new XYRect( b_r , t_l );

graphics.pushContext(rect, 0, 0);
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
graphics.popContext();

graphics.drawRect(15, 15, 30, 30);

graphics.pushContext(rect, 0, 0);
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
graphics.popContext();

graphics.drawRect(15, 15, 30, 30);
}

}

Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Why we use , pushContext() amd popContext() method in blackberry , because they dont create any effect in screen !

[ Edited ]

Push saves the state of the context so you can make changes to it, then reset it back with a pop.

Contributor
tusharpandey
Posts: 10
Registered: ‎01-19-2013
My Device: 9900

Re: Why we use , pushContext() amd popContext() method in blackberry , because they dont create any effect in screen !

But what is the benifit , because every next time you have to draw it again .

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

Re: Why we use , pushContext() amd popContext() method in blackberry , because they dont create any effect in screen !

In the example you have given, there is no benefit.  It is of more benefit when you are passing a grahics area to another method, perhaps the paint method of a super class.