79£®mPointµÄÆäËü Method
|
![BACKWARD](backward.gif) ![FORWARD](forward.gif) |
- import java.awt.*; /* Imports Graphics Method for display */
- public class mPoint { /* Continue as before and add */
- public void setColor(Color color) {this.color=color;}
- public void checkBoundry(Rectangle rect) { /* check if object crosses
boundary */
- int nx = x+dx; /* caculate new location */
- int ny = y+dy;
- if ( (nx < rect.x) || (nx >= rect.x+rect.width) ) dx = -dx;
- if ( (ny < rect.y) || (ny >= rect.y+rect.height) ) dy = -dy;
- }
- public void move(Graphics g) { /* move object */
- x += dx; /* update location */
- y += dy;
- paint(g);
- }
- public void paint(Graphics g) /* actually draw point */
- { g.setColor(color);
}
Copyright: NPACT |
![BACKWARD](backward.gif) ![FORWARD](forward.gif) |