02-03-2013 11:08 PM
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);
}
}
Solved! Go to Solution.
02-04-2013 12:12 AM - edited 02-04-2013 12:14 AM
Push saves the state of the context so you can make changes to it, then reset it back with a pop.
02-04-2013 02:16 AM
But what is the benifit , because every next time you have to draw it again .
02-04-2013 08:37 AM
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.