MainScreen mScreen = new MainScreen(DEFAULT_MENU | DEFAULT_CLOSE);
Manage a drawing area
The
Graphics
object represents the entire drawing surface that is available to the BlackBerry® device application. To limit
this area, divide it into
XYRect
objects. Each
XYPoint
represents a point on the screen, which is composed of an X co-
ordinate and a Y co-ordinate.
1.
Import the following classes:
•
net.rim.device.api.ui.Graphics
•
net.rim.device.api.ui.XYRect
•
net.rim.device.api.ui.XYPoint
2.
Create an instance of an
XYPoint
object and an
XYRect
object.
XYPoint bottomRight = new XYPoint(50, 50);
XYRect rectangle = new XYRect(topLeft, bottomRight);
XYPoint topLeft = new XYPoint(10, 10);
3.
Invoke
Graphics.pushContext()
to make drawing calls that specify that the region origin should not adjust the
drawing offset. In the following code sample, we create two
XYPoint
objects to represent the top left and bottom right
points of a rectangle. We then create a rectangular clipping region by creating an
XYRect
object using the
XYPoint
objects. We invoke
Graphics.pushContext()
to push the rectangular clipping region to the context stack. We
invoke
Graphics.drawRect()
to draw a rectangle and invoke
Graphics.fillRect()
to fill a rectangle. We
invoke
Graphics.popContext()
to pop the current context off of the context stack.
XYPoint bottomRight = new XYPoint(50, 50);
XYPoint topLeft = new XYPoint(10, 10);
XYRect rectangle = new XYRect(topLeft, bottomRight);
graphics.pushContext(rectangle, 0, 0);
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
graphics.popContext();
graphics.drawRect(15, 15, 30, 30);
graphics.pushContext(rectangle, 0, 0);
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
graphics.popContext();
graphics.drawRect(15, 15, 30, 30);
4.
Invoke
pushRegion()
and specify that the region origin should adjust the drawing offset. In the following code sample,
we invoke
Graphics.drawRect()
to draw a rectangle and invoke
Graphics.fillRect()
to fill a rectangle.
We invoke
Graphics.popContext()
to pop the current context off of the context stack.
Development Guide
Screens
9