![]()
Lab 4 Method Applet Source Code![]()

//Keith Adams, September 6, 2000
//This program is an applet that
//will display my first and last
//name, draw three colored concentric
//rings, and display the scoring
//values for each ring.
//It will also draw a 5x5 checkerboard
import java.awt.*;
import java.applet.Applet;
public class Archery2 extends Applet
{
public void paint (Graphics window)
{
window.drawString("Keith Adams",200,40);
draw_target(window);
draw_board(window,10,10,30);
}
private void draw_target (Graphics window)
{
//draw a target with three circles
draw_circles(window, 400, 400, 300,Color.blue,50);
draw_circles(window, 400, 400, 200,Color.green,100);
draw_circles(window, 400,400,100,Color.red,200);
}
private void draw_circles (Graphics window, int centerX,
int centerY,int radius,
Color circle_color,int score)
{
//draw a circle with a point value
window.setColor(circle_color);
window.fillOval(centerX-radius,centerY-radius,2*radius,2*radius);
window.setColor(Color.white);
window.drawString(score+" points",centerX+radius-80,centerY+10);
}
//add 5x5 checker board
private void draw_square (Graphics window, Color square_color, int left, int top, int size)
{
//set color and draw square
window.setColor (square_color);
window.fillRect(left,top,size,size);
}
private void draw_row1 (Graphics window,int topX,int topY,int size)
{
//draw a row of five squares
draw_square(window,Color.black,topX,topY,size);
draw_square(window,Color.red,topX+size,topY,size);
draw_square(window,Color.black,topX+2*size,topY,size);
draw_square(window,Color.red, topX+3*size,topY,size);
draw_square(window,Color.black,topX+4*size,topY,size);
}
private void draw_row2 (Graphics window, int topX,int topY,int size)
{
//draw a row of five squares (of opposite color alternation)
draw_square(window,Color.red,topX,topY,size);
draw_square(window,Color.black,topX+size,topY,size);
draw_square(window,Color.red,topX+2*size,topY,size);
draw_square(window,Color.black, topX+3*size,topY,size);
draw_square(window,Color.red,topX+4*size,topY,size);
}
private void draw_board (Graphics window,int startX,int startY,int length)
{
//draw 5 rows (alternating between the two color alternations)
draw_row1(window,startX,startY,length);
draw_row2(window,startX,startY+length,length);
draw_row1(window,startX,startY+2*length,length);
draw_row2(window,startX,startY+3*length,length);
draw_row1(window,startX,startY+4*length,length);
}
}