Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bullseye

Status
Not open for further replies.

bigred925

MIS
Jul 6, 2001
15
US
I have this sample code, how do I make the bullseye center and resize when the size of the applet is changed by a user?

public class Bullseye extends Applet
{

private final int MAX_WIDTH = 300;
private final int NUM_RINGS = 5;
private final int RING_WIDTH = 25;

//--------------------------------------------
//paints a bullseye target
//--------------------------------------------

public void paint (Graphics page)

{
int x = 0, y = 0, diameter;
setBackground (Color.cyan);

diameter = MAX_WIDTH;
page.setColor (Color.white);

for (int count = 0; count < NUM_RINGS; count++)
{

if (page.getColor() == Color.black) // alternate colors
page.setColor (Color.white);

else
page.setColor (Color.black);

page.fillOval (x, y, diameter, diameter);

diameter -= (2 * RING_WIDTH);
x += RING_WIDTH;
y += RING_WIDTH;


}

// Draw the red bullseye in the center
page.setColor (Color.red);
page.fillOval (x, y, diameter, diameter);


}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top