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


1 public void paint( Graphics g ) {
2 Graphics2D g2d = ( Graphics2D ) g;
3 g2d.setColor( Color.red );
4 GeneralPath rect = new GeneralPath( GeneralPath.EVEN_ODD );
5 rect.moveTo( 300.0f, 300.0f ); // ul corner
6 rect.lineTo( 500.0f, 300.0f ); // ur corner
7 rect.lineTo( 500.0f, 400.0f ); // lr corner
8 rect.lineTo( 300.0f, 400.0f ); // ll corner
9 rect.closePath(); // close the rectangle
10 g2d.fill( rect );
11 }

in Table To:


© 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