Troubleshooting guide

43
1: Creating UIs
Manage foreground events
The system calls Application.activate() when it brings an application to the foreground.
Manage drawing areas
The Graphics object represents the entire drawing surface that is available to the 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.
Task Steps
Create rectangular clipping areas. 1. 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);
2. Invoke pushContext() or pushRegion().
3. When you make drawing calls with pushContext(), specify that the region origin should not
adjust the drawing offset.
graphics.pushContext(rectangle, 0, 0);
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
graphics.popContext();
4. When you invoke drawing methods by first calling pushRegion(), specify that the region origin
should adjust the drawing offset.
graphics.pushRegion(rectangle);
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
graphics.popRegion();
Invert an area. 1. Invert a specified XYRect object.
2. Specify the portion of the Graphics object to push onto the stack.
3. After you invoke pushContext() (or pushRegion()), provide the portion of the Graphics
object to invert.
graphics.pushContext(rectangle);
graphics.invert(rectangle); // invert the entire XYRect object
graphics.popContext();
Translate an area. >Invoke translate(). The XYRect translates from its origin of (1, 1) to an origin of (20, 20). After
translation, the bottom portion of the
XYRect object extends past the bounds of the graphics
context and clips it.
XYRect rectangle = new XYRect(1, 1, 100, 100);
XYPoint newLocation = new XYPoint(20, 20);
rectangle.translate(newLocation);