Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Default Adding stuff to my JPanel

    So, I set up my basic JFrame with a JPanel, im not sure how I could add a object to this JPanel...how would I add Paint(just a example).
    Thanks in advance!

    Java Code:
    package test;
    
    import java.awt.*;
    import javax.swing.*;
    
    public class Test{
        
        public Test(){}
        
        public void Player(){
        
        }
        
        public void Paint(Graphics g){
            
            g.drawString("1111111",55,55);
        }
        
        private static void createAndShowGUI() {
    //Frame
            JFrame GameFrame = new JFrame("TEST");
            GameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            GameFrame.pack();
            GameFrame.setVisible(true);
            GameFrame.setSize(800, 600);
            GameFrame.setResizable(false);
            GameFrame.add(GamePanel);
    //Panel
            JPanel GamePanel = new JPanel();
            GamePanel.setVisible(true);
        }
        
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default Re: Adding stuff to my JPanel

    GamePanel.add(new ???());

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Adding stuff to my JPanel

    It about just adding element to the panel. Just think about if you add a button without considering the layout to panel how it display.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Adding stuff to my JPanel

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Adding dynamic Jpanel
    By seth in forum AWT / Swing
    Replies: 3
    Last Post: 09-10-2011, 03:39 AM
  2. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 07:52 PM
  3. Adding Jpanel ontop of another Jpanel
    By Manfizy in forum AWT / Swing
    Replies: 4
    Last Post: 03-05-2011, 11:34 PM
  4. adding integer to the JPanel
    By navid in forum New To Java
    Replies: 2
    Last Post: 12-18-2010, 05:26 PM
  5. Looking for help on drawing stuff in a jPanel
    By Gatts79 in forum AWT / Swing
    Replies: 3
    Last Post: 08-28-2009, 07:00 PM

Posting Permissions

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