1  /*
  2   *  File:  OvalTest3.java
  3   *
  4   *  Draw a dart board
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.applet.Applet;
 11  import java.awt.Graphics;
 12  import java.awt.Color;
 13  
 14  public class OvalTest3 extends Applet {
 15  
 16     private int x = 75;  // center of dart board:  x-coordinate
 17     private int y = 75;  // center of dart board:  y-coordinate
 18     private int r = 70;  // radius of dart board
 19     private int w =  4;  // width of bands
 20     
 21     public void paint( Graphics g ) {
 22     
 23        // draw the outer band:
 24        g.drawOval( x - r, y - r, 2*r, 2*r );
 25        g.drawOval( x - r + w, y - r + w, 2*(r - w), 2*(r - w) );
 26        
 27        // draw the middle band:
 28        g.drawOval( x - r/2 - w, y - r/2 - w, r + 2*w, r + 2*w );
 29        g.drawOval( x - r/2, y - r/2, r, r );
 30        
 31        // draw the spokes:
 32        for ( int n = 0; n < 16; n++ ) {
 33           double theta = 2 * Math.PI * n/16;
 34           int xn = ( int ) Math.round( r * Math.cos( theta ) );
 35           int yn = ( int ) Math.round( r * Math.sin( theta ) );
 36           g.drawLine( x, y, xn + x, yn + y );
 37        }
 38        
 39        // draw the bullseye:
 40        g.setColor( getBackground() );
 41        g.fillOval( x - 2*w, y - 2*w, 4*w, 4*w );
 42        g.setColor( getForeground() );
 43        g.drawOval( x - 2*w, y - 2*w, 4*w, 4*w );
 44        g.drawOval( x - w, y - w, 2*w, 2*w );
 45        
 46     }
 47     
 48  }