<< Chapter < Page | Chapter >> Page > |
What does the actionPerformed method do?
There is nothing complicated about the code in Listing 12 . This code performs the following actions as indicated by the embedded comments:
The setCoordinateFrame method
This method, which is shown in Listing 13 , is used to set the coordinate frame of the off-screen image by setting the origin to the specified offsetvalues relative to origin of the world coordinate frame.
Listing 13 . The setCoordinateFrame method. |
---|
private void setCoordinateFrame(
Graphics2D g2D,double xOff,double yOff){//Paint the background white
g2D.setColor(Color.WHITE);g2D.fillRect(0,0,osiWidth,osiHeight);
//Translate the origin by the specified amountg2D.translate((int)xOff,(int)yOff);
//Draw new X and Y-axes in BLACKg2D.setColor(Color.BLACK);
g2D.drawLine(-(int)xOff,0,(int)(osiWidth-xOff),0);g2D.drawLine(0,-(int)yOff,0,(int)((osiHeight-yOff)));
}//end setCoordinateFrame method |
What does the setCoordinateFrame method do?
As mentioned earlier, the origin of the world coordinate frame is the upper-left corner of the off-screen image. The setCoordinateFrame method assumes that the current coordinate frame coincides with the world coordinateframe when the method is called. This is because the method changes the coordinate frame relative to the current coordinate frame.
The method begins by painting the background white erasing anything already there. (Note that this step erases the entire image only when the coordinate frame coincides with the world coordinate frame when the method is called.)
Then the method establishes the new coordinate frame by translating the origin of the off-screen image using the X and Y offset values received asincoming parameters.
Finally, the method draws black orthogonal axes intersecting at the origin of the new coordinate frame on the off-screen image.
Beginning of the drawOffScreen method
The code for the method named drawOffScreen begins in Listing 14 . This method is called once in the constructor for the GUI class (see Listing 21 ) , and again each time the user clicks the Replot button shown in Figure 2 .
The purpose of this method is to create some Vector objects and to cause visual manifestations of the Vector objects to be drawn onto an off-screen image.
Listing 14 . Beginning of the drawOffScreen method. |
---|
void drawOffScreen(Graphics2D g2D){
setCoordinateFrame(g2D,xOffset,yOffset); |
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?