How does pack() work and what does it looks for
<p>I was messing with some code and came across the pack method which is suppose to find the "optimum" size for a window. But when I tried to out it simply made a window as small as possible even though I drew a circle before calling pack(). Why is that? What elements does pack() look for? I also frequently have found code that uses both pack() and setSize() which Oracle explicitly says not to do. What is the point since they both set size?</p>

<p>Here is that part of the code incase it was me who did something wrong:</p>

<pre><code>    public void paint(Graphics g) {
        super.paint(g);
        g.fillOval(x, y, 30, 30);
    }

    public static void main(String[] args) throws InterruptedException {
        JFrame frame = new JFrame("Extreme Pong");
        Game game = new Game();
        frame.add(game);
        frame.pack();
}
</code></pre>

<p>Edit:
Apparently I either was not clear to most of you since the linked answer to the "duplicate" did not answer my question. The mad programmer did answer my question, so thank you to you.</p>