Basic HTML version of Foils prepared May 12 1996

Foil 60 Some More Methods for mPoint

From CRPC Lectures on Java Language Applets Graphics CRPC Annual Meeting Tutorial -- May 14,1996. by Geoffrey C. Fox


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 Sun Dec 14 1997