I need this target for an interface I’m working on… It has to re-size and have several rings of alternating colors. I was able to get 1 circle that resizes but am unsure how to make more circles(obviously smaller and to some sort of ratio to make a target). I tried making another g.fillOval with different values but it wasn’t making the target like pattern I wanted. Thanks in advance!
package target;
import java.awt.*;
import javax.swing.*;
import java.applet.*;
public class Target extends JPanel //Setting up a graphics window
{
public Target()
{
setBackground(Color.BLACK); //Color constant
setPreferredSize(new Dimension(250,250));
}
public void paintComponent(Graphics g)
{
Dimension d = getSize();
int x = d.width/2;
int y = d.height/2;
int radius = (int) ((d.width < d.height) ? 0.4 * d.width : 0.4 * d.height);
int width = getWidth(); // width of window in pixels
int height = getHeight(); // height of window in pixels
super.paintComponent(g); // call superclass to display the panel
//Drawing code below
g.setColor(Color.cyan);
g.fillOval(x-radius, y-radius, 2*radius, 2*radius);
//Here is where I'm not sure! If I do another g.fillOval, I have no clue what i'd change the values to be.
}
public static void main(String[] args)
{
Target panel = new Target(); // window for drawing
JFrame application = new JFrame(); // the program itself
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set frame to exit when it is closed
application.add(panel);
application.setTitle("Target Program");
application.setSize(500, 500); // window is 500 pixels wide, 400 high
application.setVisible(true);
}
}