Web file server - 620 Graphics and Java2D Chapter 11 The application
620 Graphics and Java2D Chapter 11 The application of Fig. 11.14 demonstrates drawing a variety of lines, rectangles, 3D rectangles, rounded rectangles and ovals. 1 // Fig. 11.14: LinesRectsOvals.java 2 // Drawing lines, rectangles and ovals 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class LinesRectsOvals extends JFrame { 12 13 // set window’s title bar String and dimensions 14 public LinesRectsOvals() 15 { 16 super( “Drawing lines, rectangles and ovals” ); 17 18 setSize( 400, 165 ); 19 setVisible( true ); 20 } 21 22 // display various lines, rectangles and ovals 23 public void paint( Graphics g ) 24 { 25 // call superclass’s paint method 26 super.paint( g ); 27 28 g.setColor( Color.red ); 29 g.drawLine( 5, 30, 350, 30 ); 30 31 g.setColor( Color.blue ); 32 g.drawRect( 5, 40, 90, 55 ); 33 g.fillRect( 100, 40, 90, 55 ); 34 35 g.setColor( Color.cyan ); 36 g.fillRoundRect( 195, 40, 90, 55, 50, 50 ); 37 g.drawRoundRect( 290, 40, 90, 55, 20, 20 ); 38 39 g.setColor( Color.yellow ); 40 g.draw3DRect( 5, 100, 90, 55, true ); 41 g.fill3DRect( 100, 100, 90, 55, false ); 42 43 g.setColor( Color.magenta ); 44 g.drawOval( 195, 100, 90, 55 ); 45 g.fillOval( 290, 100, 90, 55 ); 46 } 47 Fig. 11.14 Demonstrating Graphicsmethod drawLine(part 1 of 2). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01