Basic HTML version of Foils prepared May 19 99

Foil 14 Drawing a Rectangle with Java 2D

From Java Media Framework API's Basic Information Track Computational Science Course CPS616 -- Spring Semester 1999. by Byeongseob Ki, Scott Klasky, Nancy McCracken


public void paint( Graphics g ) {
Graphics2D g2d = ( Graphics2D ) g;
g2d.setColor( Color.red );
GeneralPath rect = new GeneralPath( GeneralPath.EVEN_ODD );
rect.moveTo( 300.0f, 300.0f ); // ul corner
rect.lineTo( 500.0f, 300.0f ); // ur corner
rect.lineTo( 500.0f, 400.0f ); // lr corner
rect.lineTo( 300.0f, 400.0f ); // ll corner
rect.closePath(); // close the rectangle
g2d.fill( rect );
}



© 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 Mon Jul 5 1999