HELP! * GREY=local LOCAL HTML version of Foils prepared 29 January 1996

Foil 64 Some More Methods for mPoint

From CPS616 Lectures on Java CPS616 Basic Information Track for Computational Science -- Winter-Spring Semester 96. by Geoffrey C. Fox * See also color IMAGE

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 */
    • paint(g); /* use XOR to hide object */
    • x += dx; /* update location */
    • y += dy;
    • paint(g); /* draw object on new location */
  • }
    • public void paint(Graphics g) {}
}



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Feb 18 1997