Results 1 to 3 of 3
  1. #1
    tooktook22 is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Default adding multiple jpanels to content pane

    hi, is it possible to display another jpanel in the frame instead of opening a new frame each time?


    public void actionPerformed(ActionEvent e)
    {
    JFrame aFrame = new JFrame();
    aFrame.setBounds(0,0,400,600);
    Container contentPane = aFrame.getContentPane();
    JButton s = (JButton)e.getSource();
    if(s == attack)
    {
    contentPane.add(new Attack());
    }
    else if(s == defense)
    {
    contentPane.add(new Defense());
    }
    aFrame.setVisible(true);

    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

Similar Threads

  1. Centering things a content pane
    By RKhadder in forum New To Java
    Replies: 1
    Last Post: 09-28-2010, 02:43 AM
  2. Update the JFrame after change the Content Pane
    By alisonchan30 in forum AWT / Swing
    Replies: 1
    Last Post: 04-26-2010, 07:22 AM
  3. Dynamically adding JPanels to the JTabbedPane !!
    By Stephen Douglas in forum New To Java
    Replies: 1
    Last Post: 04-12-2010, 06:54 PM
  4. Changing content pane of a JFrame?
    By dunafrothint in forum AWT / Swing
    Replies: 1
    Last Post: 03-11-2010, 11:21 PM
  5. Replies: 3
    Last Post: 01-06-2008, 12:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •