javajframecontentpane

JFrame and Container


im really stuck, i have to define the container object by associating it with the JFrame in order to get my JFrame working with all its components.

my code is follows:

// get content pane for attaching GUI components
  Container contentPane = getContentPane();

my JFrame i wish to call it billFrame, I also want to call my container billContentPane, so im looking for something like:

private JFrame billFrame = new JFrame();

Would the above code be correct, or what would i have to change? would an instance variable have to be declared or am i way off the mark?


Solution

  • You could do the following 2 things:

    JFrame billFrame = new JFrame();
    Container billContentPane = billFrame.getContentPane();
    

    or

    JFrame billFrame = new JFrame();
    JPanel billContentPane = new JPanel();
    bilFrame.setContentPane(billContentPane);
    

    Of course you can have whatever identifiers you want [private or public].

    Also as a note you should run these 2 commands to show your frame:

    billFrame.pack();
    billFrame.setVisible(true);