Basic HTML version of Foils prepared April 7 1998

Foil 9 Drawing a Rectangle with Java 2D

From Overview of Java2D and Java3D Frameworks CPS616 Web Technologies -- Spring 98. by Geoffrey C. Fox


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 Sun May 3 1998