拡張するクラスとWindow
拡張JFrame
するクラスContent
がありますJPanel
。のオブジェクトが のオブジェクトにContent
追加されますWindow
。
クラスWindow
:
public class Window extends JFrame
{
private Content content;
public Window()
{
setTitle("My Window");
setSize(800, 600);
setResizable(false);
setLocationRelativeTo(getParent());
setDefaultCloseOperation(EXIT_ON_CLOSE);
content = new Content(this);
add(content);
setVisible(true);
}
public static void main(String[] args)
{
new Window();
}
}
クラスContent
:
public class Content extends JPanel
{
public Content(Window w)
{
window = w;
System.out.println(window.getContentPane().getWidth());
}
}
ここで、コンテンツ ペインの幅を知る必要があります。しかし、window.getContentPane().getWidth()
0 を返します。
なぜか教えてくれますか?