HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 79 Some More Methods for mPoint

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * Important Information in 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 */
    • x += dx; /* update location */
    • y += dy;
    • paint(g);
  • }
  • public void paint(Graphics g) /* actually draw point */
  • { g.setColor(color);
    • g.drawOval(x,y,1,1);}
}



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