/* SimpleDraw.java * * Examples of drawing using the basic AWT graphics methods. * * Bruce M. Bolden * January 16, 1998 * http://www.cs.uidaho.edu/~bruceb/ */ import java.awt.*; import corejava.*; public class SimpleDraw extends CloseableFrame { static final int FRAME_WIDTH = 200; static final int FRAME_HEIGHT = 200; public static void main( String args[] ) { System.out.println( "Simple Draw" ); CloseableFrame f = new SimpleDraw(); f.setTitle( "Simple Draw" ); f.show(); // must resize or the window is not visible! f.setSize(FRAME_WIDTH, FRAME_HEIGHT); try { System.in.read(); // prevent console window from going away } catch (java.io.IOException e) {} } public void paint( Graphics g ) { g.translate( getInsets().left, getInsets().top ); g.drawLine( 0, 0, FRAME_WIDTH, FRAME_HEIGHT ); g.setColor( Color.red ); g.drawLine( 0, FRAME_HEIGHT, FRAME_WIDTH, 0 ); g.drawString( "Center", FRAME_WIDTH/2, FRAME_HEIGHT/2 ); g.drawRect( 20, 20, 20, 20 ); g.setColor( Color.green ); g.fillRect( 20, 50, 20, 20 ); g.setColor( Color.blue ); g.draw3DRect( 20, 80, 20, 20, true ); g.setColor( Color.cyan ); g.fill3DRect( 20, 110, 20, 20, true ); g.drawOval( 50, 20, 20, 20 ); g.setColor( Color.green ); g.fillOval( 50, 50, 20, 20 ); g.drawArc( 50, 80, 20, 20, 0, 180 ); g.setColor( Color.blue ); g.fillArc( 50, 110, 20, 20, 0, 90 ); } }