Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1, <code>A</code> extends <code>JFrame</code>. But the inner class <code>B</code> doesn't extend <code>JFrame</code>.</p> <p>2, In both <code>A</code> and <code>B</code>'s constructors, you invoke <code>getContentPane()</code> to get a <code>ContentPane</code> object. Since <code>B</code> doesn't extends <code>JFrame</code> and it is an inner class of <code>A</code>. So actually <code>A</code> and <code>B</code> use the same <code>ContentPane</code> object to show something.</p> <p>3, In <code>A</code>'s constructor, you have already added some components to it. And then in <code>B</code>'s constructor, you add a <code>JLabel</code> to the same <code>ContentPane</code> object. So all these components will be showed. It is not because the frame in <code>A</code> is not hiding. It is because the same <code>ContentPane</code> object is showed again.</p> <p>Solution: you can make <code>B</code> extends <code>JFrame</code>.</p> <p>In <code>A</code>'s constructor, line 26:</p> <pre><code>rframe.setSize(500, 200); rframe.setLocationRelativeTo(null); cp = getContentPane(); cp.setLayout(null); setSize(550, 300); </code></pre> <p>In <code>B</code>'s constructor, line line 74:</p> <pre><code>frm.setSize(500, 200); frm.setLocationRelativeTo(null); cp = getContentPane(); cp.setLayout(null); setSize(550, 300); </code></pre> <p>P.S. In your code, you will always create a new <code>JFrame</code> object and use it. There is no point for <code>A</code> or <code>B</code> to extends <code>JFrame</code>. Maybe it is better if you do the following changes.</p> <p>1, In class <code>A</code>, do not create a new <code>JFrame</code> object, just use <code>A</code>, since it is also a <code>JFrame</code>.</p> <p>2, In class <code>B</code>, use <code>cp = frm.getContentPane();</code> to get <code>ContentPane</code> from the <code>JFrame</code> you are actually using.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload