JAVA - creating basic 2D shapes that scale to window size
<p>I am trying to learn Java by reading and doing examples out of a textbook I found online. I was able to do an example in the book fairly easily but want to take it one step further. When I wrote the code for a program called 'concentric circles' I noticed that my circles didn't scale to the size of the window and I think it looks horrible (If I make the window too small the circles don't scale and you only see a piece of the circles. I tweaked my code and it seems to scale a little bit but looks terrible when I make my window too small or too large. I would like my 12 circles to fit the window size no matter the size of the window. I feel like I am so close but just can't seem to wrap my head around it. Any and all help is much appreciated, thanks in advance!</p>

<pre><code>import java.awt.Graphics;
import javax.swing.JPanel;

public class Circles extends JPanel
{

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);

        int width = getWidth();
        int height = getHeight();
        int x = width / 12;
        int y = height / 12;
        int buffersize = 0;

        for (int i = 0; i &lt; 12; i++)
        {
            g.drawOval(width / 2 - buffersize, height / 2 - buffersize, x + buffersize * 2, y + buffersize * 2);
            buffersize += 10;
        }
    }
}
</code></pre>

<p>Driver class</p>

<pre><code>import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author
 */
public class ConcentricCirclesTest 
{
    public static void main(String[] args)
    {
        //create a panel that will contain our drawing
        Circles panel = new Circles();

        //create a new frame to house the panel
        JFrame application = new JFrame();

        //set the frame to exit when closed
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.add(panel);
        application.setSize(350, 350);
        application.setVisible(true);

    }

}
</code></pre>