Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: problem with drawing images on JPanel

  1. #1
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default problem with drawing images on JPanel

    So I am making a simple snake game and have this problem. The pictures just doesn't load. Can anybody tell me what I did wrong?

    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    import java.util.Random;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.ImageIcon;
     
    class Snake extends JFrame {
    	Snake(String title) {
    		setTitle(title);
    		setSize(300, 300);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setVisible(true);
     
    		Container c = getContentPane();
    		c.setLayout(new BorderLayout());
    		c.add(new Board(), BorderLayout.CENTER);
    	}
     
    	public static void main(String args[ ]) {
    		new Snake("Snake game 2010 (c)");
    	}
    }
     
    class Board extends JPanel implements ActionListener {
    	private final int DELAY = 150;
    	private final int WIDTH = 300;
    	private final int HEIGHT = 300;
    	private final int DOT_SIZE = 10;
    	private final int ALL_DOTS_X = 30;
    	private final int ALL_DOTS_Y = 30;
     
    	private int x[ ] = new int[ALL_DOTS_X];
    	private int y[ ] = new int[ALL_DOTS_Y];
    	private int headX = x[(int)(ALL_DOTS_X / 2)];
    	private int headY = y[(int)(ALL_DOTS_Y / 2)];
    	private int bodyX = headX;
    	private int bodyY = headY;
    	private int appleX;
    	private int appleY;
    	private int bodySize = 3;
     
    	private boolean begining = true;
    	private boolean inGame = false;
    	private boolean left = true;
    	private boolean up = false;
    	private boolean right = false;
    	private boolean down = false;
    	private boolean appleStatus = false;
     
    	private Random random;
    	private Timer timer;
    	private Image apple;
    	private Image head;
    	private Image body;
     
    	private Color backgroundColor = Color.BLACK;
     
    	Board() {
    		setBackground(backgroundColor);
     
    		// images
    		ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
    		apple = appleIcon.getImage();
    		ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
    		head = headIcon.getImage();
    		ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
    		body = bodyIcon.getImage();
    		repaint();
     
    		for(int i = 0; i < (WIDTH / 10); i++)
    			x[i] = i * DOT_SIZE;
    		for(int i = 0; i < (HEIGHT / 10); i++)
    			y[i] = i * DOT_SIZE;
     
    		this.addKeyListener(new KeyAdapter() {
    			public void keyPressed(KeyEvent event) {
    				int keycode = event.getKeyCode();
    				if(keycode == event.VK_UP && !down) {
    					up = true;
    					right = false;
    					left = false;
    					down = false;
    				}
    				if(keycode == event.VK_LEFT && !right) {
    					left = true;
    					right = false;
    					up = false;
    					down = false;
    				}
    				if(keycode == event.VK_RIGHT && !left) {
    					right = true;
    					left = false;
    					up = false;
    					down = false;
    				}
    				if(keycode == event.VK_DOWN && !up) {
    					down = true;
    					up = false;
    					right = false;
    					left = false;
    				}
    			}
    		});
     
    		timer = new Timer(DELAY, this);
    //		timer.start();
    	}
     
    	void locateApple() {
    		appleX = x[random.nextInt(30)];
    		appleY = y[random.nextInt(30)];
    	}
     
    	public void paint(Graphics g) {
    		super.paint(g);
    		if(inGame) {
    			if(!appleStatus) {
    				locateApple();
    				g.drawImage(apple, appleX, appleY, this);
    				appleStatus = true;
    			}
     
    			g.drawImage(head, headX, headY, this);
    			for(int i = bodySize; i == 0; i--) {
    				bodyX = headX + i * DOT_SIZE;
    				bodyY = headY;
    				g.drawImage(body, bodyX, bodyY, this);
    				begining = false;
    			}
    		}
    	}
     
    	public void actionPerformed(ActionEvent event) {
    //		if(up) {
     
    //		}
    	}
    }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: problem with drawing images on JPanel

    um, do you ever set inGame to true? Cause if not, then thats your reason.

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Asido (July 19th, 2010)

  4. #3
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: problem with drawing images on JPanel

    That's embarrassing. I couldn't see that for 3 hours. But unfortunately this didn't solved the problem though. I still can't see the images.
    The previous code throws many NullPointerExceptions after changing inGame to true, so this is the version without Exceptions. I have no idea what is wrong here. I have examined many examples with loading images in JPanel this way. I am wondering, perhaps the paint method I am overriding doesn't belong to that JPanel?
    I have tryed to load them in JLabel and then add them to JPanel. This way worked, but it is not convenient since the images has to be moved when the timer ticks.
    To draw them on the JFrame worked as well, but then all the decorations would be on top of it. So not convenient again. Anyone has an idea?
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    import java.util.Random;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.ImageIcon;
     
    class Snake extends JFrame {
    	Snake(String title) {
    		setTitle(title);
    		setSize(300, 300);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setVisible(true);
     
    		Board b = new Board();
    		Container c = getContentPane();
    		c.setLayout(new BorderLayout());
    		c.add(b.panel, BorderLayout.CENTER);
    	}
     
    	public static void main(String args[ ]) {
    		new Snake("Snake game 2010 (c)");
    	}
    }
     
    class Board extends JPanel implements ActionListener {
    	private final int DELAY = 150;
    	private final int WIDTH = 300;
    	private final int HEIGHT = 300;
    	private final int DOT_SIZE = 10;
    	private final int ALL_DOTS_X = 30;
    	private final int ALL_DOTS_Y = 30;
     
    	private int x[ ] = new int[ALL_DOTS_X];
    	private int y[ ] = new int[ALL_DOTS_Y];
    	private int headX = x[(int)(ALL_DOTS_X / 2)];
    	private int headY = y[(int)(ALL_DOTS_Y / 2)];
    	private int bodyX = headX;
    	private int bodyY = headY;
    	private int appleX;
    	private int appleY;
    	private int bodySize = 3;
     
    	private boolean inGame = true;
    	private boolean left = true;
    	private boolean up = false;
    	private boolean right = false;
    	private boolean down = false;
    	private boolean appleStatus = false;
     
    	JPanel panel;
    	private Random random;
    	private Timer timer;
    	private Image apple;
    	private Image head;
    	private Image body;
     
    	private Color backgroundColor = Color.BLACK;
     
    	Board() {
    		panel = new JPanel();
    		panel.setSize(WIDTH, HEIGHT);
    		panel.setBackground(backgroundColor);
     
    		// images
    		ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
    		apple = appleIcon.getImage();
    		ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
    		head = headIcon.getImage();
    		ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
    		body = bodyIcon.getImage();
     
    		for(int i = 0; i < (WIDTH / 10); i++)
    			x[i] = i * DOT_SIZE;
    		for(int i = 0; i < (HEIGHT / 10); i++)
    			y[i] = i * DOT_SIZE;
     
    		this.addKeyListener(new KeyAdapter() {
    			public void keyPressed(KeyEvent event) {
    				int keycode = event.getKeyCode();
    				if(keycode == event.VK_UP && !down) {
    					up = true;
    					right = false;
    					left = false;
    					down = false;
    				}
    				if(keycode == event.VK_LEFT && !right) {
    					left = true;
    					right = false;
    					up = false;
    					down = false;
    				}
    				if(keycode == event.VK_RIGHT && !left) {
    					right = true;
    					left = false;
    					up = false;
    					down = false;
    				}
    				if(keycode == event.VK_DOWN && !up) {
    					down = true;
    					up = false;
    					right = false;
    					left = false;
    				}
    			}
    		});
     
    		timer = new Timer(DELAY, this);
    //		timer.start();
    	}
     
    	void locateApple() {
    		appleX = x[random.nextInt(30)];
    		appleY = y[random.nextInt(30)];
    	}
     
    	public void paint(Graphics g) {
    		super.paint(g);
    		if(inGame) {
    			if(!appleStatus) {
    				locateApple();
    				g.drawImage(apple, appleX, appleY, panel);
    				appleStatus = true;
    			}
     
    			g.drawImage(head, headX, headY, panel);
    			for(int i = bodySize; i == 0; i--) {
    				bodyX = headX + i * DOT_SIZE;
    				bodyY = headY;
    				g.drawImage(body, bodyX, bodyY, panel);
    			}
    		}
    	}
     
    	public void actionPerformed(ActionEvent event) {
    //		if(up) {
     
    //		}
    	}
    }
    Last edited by Asido; July 19th, 2010 at 01:47 PM.

  5. #4
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: problem with drawing images on JPanel

    I'd first recommend checking whether the images and ImageIcons you load are null (if's and println's work wonders for debugging). If so, then you've got a problem loading your images (make sure they are in the correct location - in your case the same directory as your .class file). If not, then you know the issue is downstream.

    EDIT: I'd also recommend performing your drawing by overriding the paintComponent method rather than the paint method.

    EDIT EDIT: After closer inspection, it seems you are drawing to a JPanel (Board) that is not added anywhere in your layout, whereas the Board.panel - which is added to your layout - has nothing drawn to it. Try calling:
    c.add(b, BorderLayout.CENTER);//rather than b.panel
    Last edited by copeg; July 19th, 2010 at 01:49 PM.

  6. #5
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: problem with drawing images on JPanel

    Well, we need to figure out where the NullPointers are at. To do this, we either set up a bunch of try/catch statements or throw in a bunch of System.out.println's. I suggest that latter.

    To place them in the correct place, we need to figure out where NullPointers could occur. That would be at the ImageIcons and the arrays as that is really the only place you set values.

    Search for a null pointer when we set these. So put something like this:
    ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
    apple = appleIcon.getImage();
    System.out.println("Apple: "+apple);
    ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
    head = headIcon.getImage();
    System.out.println("Head: "+head);
    ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
    body = bodyIcon.getImage();
    System.out.println("Body: "+body);
     
    for(int i = 0; i < (WIDTH / 10); i++)
    {
                x[i] = i * DOT_SIZE;
               System.out.println("i1: "+i+" Value: "+x[i]);
    }
    for(int i = 0; i < (HEIGHT / 10); i++)
    {
                y[i] = i * DOT_SIZE;
               System.out.println("i2: "+i+" Value: "+y[i]);
    }

    We dont particularly care about what we get, we are just looking for any value of "null"

  7. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Asido (July 19th, 2010)

  8. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: problem with drawing images on JPanel

    Quote Originally Posted by copeg View Post
    I'd first recommend checking whether the images and ImageIcons you load are null (if's and println's work wonders for debugging). If so, then you've got a problem loading your images (make sure they are in the correct location - in your case the same directory as your .class file). If not, then you know the issue is downstream.

    EDIT: I'd also recommend performing your drawing by overriding the paintComponent method rather than the paint method.

    EDIT EDIT: After closer inspection, it seems you are drawing to a JPanel (Board) that is not added anywhere in your layout, whereas the Board.panel - which is added to your layout - has nothing drawn to it. Try calling:
    c.add(b, BorderLayout.CENTER);//rather than b.panel
    You know, your on to something there, infact, the more I look at it, the more GUI problems I'm seeing.

    Snake is a JFrame. So why are we calling Container c = getContentPane();? In fact, Snake doesnt even have a Container other than itself until we give it one. Maybe that is the NullPointer. And even more importantly, Board is our JPanel.

    I think what we want is instead of:
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(b.panel, BorderLayout.CENTER);
    we want:
    b.setLayout(new BorderLayout());
    setContentPane(b);

    Plus you have Board confused. You set Board to be a JPanel, but you also constructed a JPanel inside of it.
    Board()
    {
    panel = new JPanel();
    panel.setSize(WIDTH, HEIGHT);
    panel.setBackground(backgroundColor);
    ...
    }
    That is probably your problem right there. You are setting Board's paint method, but not the paint method of the JPanel you created in board.
    Get rid of the panel thing, and just put:
    Board()
    {
    setSize(WIDTH, HEIGHT);
    setBackground(backgroundColor);
    ...
    }

    This way, the changes we are making to the paint method will effect the JPanel our JFrame is using as the ContentPane.
    Last edited by aussiemcgr; July 19th, 2010 at 02:07 PM.

  9. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Asido (July 19th, 2010)

  10. #7
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: problem with drawing images on JPanel

    Quote Originally Posted by aussiemcgr View Post
    Well, we need to figure out where the NullPointers are at. To do this, we either set up a bunch of try/catch statements or throw in a bunch of System.out.println's. I suggest that latter.

    To place them in the correct place, we need to figure out where NullPointers could occur. That would be at the ImageIcons and the arrays as that is really the only place you set values.

    Search for a null pointer when we set these. So put something like this:
    ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
    apple = appleIcon.getImage();
    System.out.println("Apple: "+apple);
    ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
    head = headIcon.getImage();
    System.out.println("Head: "+head);
    ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
    body = bodyIcon.getImage();
    System.out.println("Body: "+body);
     
    for(int i = 0; i < (WIDTH / 10); i++)
    {
                x[i] = i * DOT_SIZE;
               System.out.println("i1: "+i+" Value: "+x[i]);
    }
    for(int i = 0; i < (HEIGHT / 10); i++)
    {
                y[i] = i * DOT_SIZE;
               System.out.println("i2: "+i+" Value: "+y[i]);
    }

    We dont particularly care about what we get, we are just looking for any value of "null"
    Looking at the output after doing that looks everything ok.
    apple: sun.awt.image.ToolkitImage@5fcf29                                 
    head: sun.awt.image.ToolkitImage@125844f                                 
    body: sun.awt.image.ToolkitImage@f7c31d                                  
    i1: 0 Value: 0                                                           
    i1: 1 Value: 10                                                          
    i1: 2 Value: 20                                                          
    i1: 3 Value: 30                                                          
    i1: 4 Value: 40                                                          
    i1: 5 Value: 50                                                          
    i1: 6 Value: 60                                                          
    i1: 7 Value: 70                                                          
    i1: 8 Value: 80                                                          
    i1: 9 Value: 90                                                          
    i1: 10 Value: 100                                                        
    i1: 11 Value: 110                                                        
    i1: 12 Value: 120                                                        
    i1: 13 Value: 130                                                        
    i1: 14 Value: 140                                                        
    i1: 15 Value: 150                                                        
    i1: 16 Value: 160                                                        
    i1: 17 Value: 170                                                        
    i1: 18 Value: 180                                                        
    i1: 19 Value: 190                                                        
    i1: 20 Value: 200                                                        
    i1: 21 Value: 210                                                        
    i1: 22 Value: 220                                                        
    i1: 23 Value: 230                                                        
    i1: 24 Value: 240                                                        
    i1: 25 Value: 250                                                        
    i1: 26 Value: 260                                                        
    i1: 27 Value: 270                                                        
    i1: 28 Value: 280                                                        
    i1: 29 Value: 290                                                        
    i2: 0 Value: 0                                                           
    i2: 1 Value: 10                                                          
    i2: 2 Value: 20                                                          
    i2: 3 Value: 30                                                          
    i2: 4 Value: 40                                                          
    i2: 5 Value: 50                                                          
    i2: 6 Value: 60                                                          
    i2: 7 Value: 70                                                          
    i2: 8 Value: 80                                                          
    i2: 9 Value: 90
    i2: 10 Value: 100
    i2: 11 Value: 110
    i2: 12 Value: 120
    i2: 13 Value: 130
    i2: 14 Value: 140
    i2: 15 Value: 150
    i2: 16 Value: 160
    i2: 17 Value: 170
    i2: 18 Value: 180
    i2: 19 Value: 190
    i2: 20 Value: 200
    i2: 21 Value: 210
    i2: 22 Value: 220
    i2: 23 Value: 230
    i2: 24 Value: 240
    i2: 25 Value: 250
    i2: 26 Value: 260
    i2: 27 Value: 270
    i2: 28 Value: 280
    i2: 29 Value: 290

  11. #8
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: problem with drawing images on JPanel

    Quote Originally Posted by Asido View Post
    Looking at the output after doing that looks everything ok.
    apple: sun.awt.image.ToolkitImage@5fcf29                                 
    head: sun.awt.image.ToolkitImage@125844f                                 
    body: sun.awt.image.ToolkitImage@f7c31d                                  
    i1: 0 Value: 0                                                           
    i1: 1 Value: 10                                                          
    i1: 2 Value: 20                                                          
    i1: 3 Value: 30                                                          
    i1: 4 Value: 40                                                          
    i1: 5 Value: 50                                                          
    i1: 6 Value: 60                                                          
    i1: 7 Value: 70                                                          
    i1: 8 Value: 80                                                          
    i1: 9 Value: 90                                                          
    i1: 10 Value: 100                                                        
    i1: 11 Value: 110                                                        
    i1: 12 Value: 120                                                        
    i1: 13 Value: 130                                                        
    i1: 14 Value: 140                                                        
    i1: 15 Value: 150                                                        
    i1: 16 Value: 160                                                        
    i1: 17 Value: 170                                                        
    i1: 18 Value: 180                                                        
    i1: 19 Value: 190                                                        
    i1: 20 Value: 200                                                        
    i1: 21 Value: 210                                                        
    i1: 22 Value: 220                                                        
    i1: 23 Value: 230                                                        
    i1: 24 Value: 240                                                        
    i1: 25 Value: 250                                                        
    i1: 26 Value: 260                                                        
    i1: 27 Value: 270                                                        
    i1: 28 Value: 280                                                        
    i1: 29 Value: 290                                                        
    i2: 0 Value: 0                                                           
    i2: 1 Value: 10                                                          
    i2: 2 Value: 20                                                          
    i2: 3 Value: 30                                                          
    i2: 4 Value: 40                                                          
    i2: 5 Value: 50                                                          
    i2: 6 Value: 60                                                          
    i2: 7 Value: 70                                                          
    i2: 8 Value: 80                                                          
    i2: 9 Value: 90
    i2: 10 Value: 100
    i2: 11 Value: 110
    i2: 12 Value: 120
    i2: 13 Value: 130
    i2: 14 Value: 140
    i2: 15 Value: 150
    i2: 16 Value: 160
    i2: 17 Value: 170
    i2: 18 Value: 180
    i2: 19 Value: 190
    i2: 20 Value: 200
    i2: 21 Value: 210
    i2: 22 Value: 220
    i2: 23 Value: 230
    i2: 24 Value: 240
    i2: 25 Value: 250
    i2: 26 Value: 260
    i2: 27 Value: 270
    i2: 28 Value: 280
    i2: 29 Value: 290
    Then check the GUI like I suggested while you were writing this. If the problem isnt with our set variables, it must be with the GUI.

  12. #9
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: problem with drawing images on JPanel

    I did like aussiemcgr suggested me, but now I get tons of NullPointerExceptions.
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException    
            at Board.locateApple(Snake.java:132)                             
            at Board.paint(Snake.java:140)                                   
            at javax.swing.JComponent.paintChildren(JComponent.java:862)     
            at javax.swing.JComponent.paint(JComponent.java:1038)            
            at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)         
            at javax.swing.JComponent.paintChildren(JComponent.java:862)     
            at javax.swing.JComponent.paint(JComponent.java:1038)            
            at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124) 
            at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)                                                                  
            at javax.swing.RepaintManager.paint(RepaintManager.java:1224)          
            at javax.swing.JComponent._paintImmediately(JComponent.java:5072)      
            at javax.swing.JComponent.paintImmediately(JComponent.java:4882)       
            at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
            at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
            at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
            at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Code looks like this:
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    import java.util.Random;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.ImageIcon;
     
    class Snake extends JFrame {
        Snake(String title) {
            setTitle(title);
            setSize(300, 300);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
     
    //        Container c = getContentPane();
    //        c.setLayout(new BorderLayout());
    //        c.add(new Board(), BorderLayout.CENTER);
    		Board b = new Board();
    		b.setLayout(new BorderLayout());
    		setContentPane(b);
        }
     
        public static void main(String args[ ]) {
            new Snake("Snake game 2010 (c)");
        }
    }
     
    class Board extends JPanel implements ActionListener {
        private final int DELAY = 150;
        private final int WIDTH = 300;
        private final int HEIGHT = 300;
        private final int DOT_SIZE = 10;
        private final int ALL_DOTS_X = 30;
        private final int ALL_DOTS_Y = 30;
     
        private int x[ ] = new int[ALL_DOTS_X];
        private int y[ ] = new int[ALL_DOTS_Y];
        private int headX = x[(int)(ALL_DOTS_X / 2)];
        private int headY = y[(int)(ALL_DOTS_Y / 2)];
        private int bodyX = headX;
        private int bodyY = headY;
        private int appleX;
        private int appleY;
        private int bodySize = 3;
     
        private boolean inGame = true;
        private boolean left = true;
        private boolean up = false;
        private boolean right = false;
        private boolean down = false;
        private boolean appleStatus = false;
     
        JPanel panel;
        private Random random;
        private Timer timer;
        private Image apple;
        private Image head;
        private Image body;
     
        private Color backgroundColor = Color.BLACK;
     
        Board() {
            setSize(WIDTH, HEIGHT);
            setBackground(backgroundColor);
     
            // images
            ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
            apple = appleIcon.getImage();
    //        System.out.println("apple: " + apple);
            ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
            head = headIcon.getImage();
    //        System.out.println("head: " + head);
            ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
            body = bodyIcon.getImage();
    //        System.out.println("body: " + body);
     
            for(int i = 0; i < (WIDTH / 10); i++) {
                x[i] = i * DOT_SIZE;
    //            System.out.println("i1: " + i + " Value: " + x[i]);
            }
            for(int i = 0; i < (HEIGHT / 10); i++) {
                y[i] = i * DOT_SIZE;
    //            System.out.println("i2: " + i + " Value: " + y[i]);
            }
     
            this.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent event) {
                    int keycode = event.getKeyCode();
                    if(keycode == event.VK_UP && !down) {
                        up = true;
                        right = false;
                        left = false;
                        down = false;
                    }
                    if(keycode == event.VK_LEFT && !right) {
                        left = true;
                        right = false;
                        up = false;
                        down = false;
                    }
                    if(keycode == event.VK_RIGHT && !left) {
                        right = true;
                        left = false;
                        up = false;
                        down = false;
                    }
                    if(keycode == event.VK_DOWN && !up) {
                        down = true;
                        up = false;
                        right = false;
                        left = false;
                    }
                }
            });
     
            timer = new Timer(DELAY, this);
    //      timer.start();
        }
     
        void locateApple() {
            appleX = x[random.nextInt(30)];
            appleY = y[random.nextInt(30)];
        }
     
        public void paint(Graphics g) {
            super.paint(g);
            if(inGame) {
                if(!appleStatus) {
                    locateApple();
                    g.drawImage(apple, appleX, appleY, this);
                    appleStatus = true;
                }
     
                g.drawImage(head, headX, headY, this);
                for(int i = bodySize; i == 0; i--) {
                    bodyX = headX + i * DOT_SIZE;
                    bodyY = headY;
                    g.drawImage(body, bodyX, bodyY, this);
                }
            }
        }
     
        public void actionPerformed(ActionEvent event) {
    //      if(up) {
     
    //      }
        }
    }

    EDIT: Finally I managed to see the images after commenting the lines (132 and 140) which throws NullPointsException!
    Last edited by Asido; July 19th, 2010 at 02:24 PM.

  13. #10
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: problem with drawing images on JPanel

    Quote Originally Posted by Asido View Post
    I did like aussiemcgr suggested me, but now I get tons of NullPointerExceptions.
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException    
            at Board.locateApple(Snake.java:132)                             
            at Board.paint(Snake.java:140)                                   
            at javax.swing.JComponent.paintChildren(JComponent.java:862)     
            at javax.swing.JComponent.paint(JComponent.java:1038)            
            at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)         
            at javax.swing.JComponent.paintChildren(JComponent.java:862)     
            at javax.swing.JComponent.paint(JComponent.java:1038)            
            at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124) 
            at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)                                                                  
            at javax.swing.RepaintManager.paint(RepaintManager.java:1224)          
            at javax.swing.JComponent._paintImmediately(JComponent.java:5072)      
            at javax.swing.JComponent.paintImmediately(JComponent.java:4882)       
            at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
            at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
            at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
            at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Code looks like this:
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    import java.util.Random;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.ImageIcon;
     
    class Snake extends JFrame {
        Snake(String title) {
            setTitle(title);
            setSize(300, 300);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
     
    //        Container c = getContentPane();
    //        c.setLayout(new BorderLayout());
    //        c.add(new Board(), BorderLayout.CENTER);
    		Board b = new Board();
    		b.setLayout(new BorderLayout());
    		setContentPane(b);
        }
     
        public static void main(String args[ ]) {
            new Snake("Snake game 2010 (c)");
        }
    }
     
    class Board extends JPanel implements ActionListener {
        private final int DELAY = 150;
        private final int WIDTH = 300;
        private final int HEIGHT = 300;
        private final int DOT_SIZE = 10;
        private final int ALL_DOTS_X = 30;
        private final int ALL_DOTS_Y = 30;
     
        private int x[ ] = new int[ALL_DOTS_X];
        private int y[ ] = new int[ALL_DOTS_Y];
        private int headX = x[(int)(ALL_DOTS_X / 2)];
        private int headY = y[(int)(ALL_DOTS_Y / 2)];
        private int bodyX = headX;
        private int bodyY = headY;
        private int appleX;
        private int appleY;
        private int bodySize = 3;
     
        private boolean inGame = true;
        private boolean left = true;
        private boolean up = false;
        private boolean right = false;
        private boolean down = false;
        private boolean appleStatus = false;
     
        JPanel panel;
        private Random random;
        private Timer timer;
        private Image apple;
        private Image head;
        private Image body;
     
        private Color backgroundColor = Color.BLACK;
     
        Board() {
            setSize(WIDTH, HEIGHT);
            setBackground(backgroundColor);
     
            // images
            ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
            apple = appleIcon.getImage();
    //        System.out.println("apple: " + apple);
            ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
            head = headIcon.getImage();
    //        System.out.println("head: " + head);
            ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
            body = bodyIcon.getImage();
    //        System.out.println("body: " + body);
     
            for(int i = 0; i < (WIDTH / 10); i++) {
                x[i] = i * DOT_SIZE;
    //            System.out.println("i1: " + i + " Value: " + x[i]);
            }
            for(int i = 0; i < (HEIGHT / 10); i++) {
                y[i] = i * DOT_SIZE;
    //            System.out.println("i2: " + i + " Value: " + y[i]);
            }
     
            this.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent event) {
                    int keycode = event.getKeyCode();
                    if(keycode == event.VK_UP && !down) {
                        up = true;
                        right = false;
                        left = false;
                        down = false;
                    }
                    if(keycode == event.VK_LEFT && !right) {
                        left = true;
                        right = false;
                        up = false;
                        down = false;
                    }
                    if(keycode == event.VK_RIGHT && !left) {
                        right = true;
                        left = false;
                        up = false;
                        down = false;
                    }
                    if(keycode == event.VK_DOWN && !up) {
                        down = true;
                        up = false;
                        right = false;
                        left = false;
                    }
                }
            });
     
            timer = new Timer(DELAY, this);
    //      timer.start();
        }
     
        void locateApple() {
            appleX = x[random.nextInt(30)];
            appleY = y[random.nextInt(30)];
        }
     
        public void paint(Graphics g) {
            super.paint(g);
            if(inGame) {
                if(!appleStatus) {
                    locateApple();
                    g.drawImage(apple, appleX, appleY, this);
                    appleStatus = true;
                }
     
                g.drawImage(head, headX, headY, this);
                for(int i = bodySize; i == 0; i--) {
                    bodyX = headX + i * DOT_SIZE;
                    bodyY = headY;
                    g.drawImage(body, bodyX, bodyY, this);
                }
            }
        }
     
        public void actionPerformed(ActionEvent event) {
    //      if(up) {
     
    //      }
        }
    }

    EDIT: Finally I managed to see the images after commenting the lines (132 and 140) which throws NullPointsException!
    2 things...
    1) Incase you dont already know, when you get a NullPointer like that, the only one we care about is the first occurance because that is the most relevent to what we are doing. The only reason it prints out all of those NullPointers is because it is tracking it backwards because none of those methods are designed to handle exceptions.
    2) What lines did you comment out that you found gives NullPointers? We cant see line numbers on your code.

  14. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Asido (July 19th, 2010)

  15. #11
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: problem with drawing images on JPanel

    132:
    appleX = x[random.nextInt(30)];
    140:
    locateApple();
    The problem is I guess because paint method is called first, and then the Board constructor which initializes x and y arrays.

  16. #12
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: problem with drawing images on JPanel

    Quote Originally Posted by aussiemcgr View Post
    In fact, Snake doesnt even have a Container other than itself until we give it one. Maybe that is the NullPointer.
    JFrame's do have an associated content pane whether it is set or not, so calling getContentPane() will not return a null pointer unless you called setContentPane(null)


    Along the lines of the NullPointerException, those descriptions should lead you to the precise location of the problem, in your case line 132....(hint: where is the variable random instantiated?)

    Once again, I encourage you to use paintComponent rather than paint

  17. #13
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,600
    Thanks
    24
    Thanked 313 Times in 293 Posts

    Default Re: problem with drawing images on JPanel

    Quote Originally Posted by Asido View Post
    132:
    appleX = x[random.nextInt(30)];
    140:
    locateApple();
    The problem is I guess because paint method is called first, and then the Board constructor which initializes x and y arrays.
    Your right, that would be the reason. We might be able to fix this though. What if you overroad the update(Graphics g) method instead of the paint(Graphics g) method? In order to prevoke that method, you would say repaint(); That way you could initialize the x and y arrays, then call repaint(); to draw the snake.

    Scratch that, it may mess up real bad. Try the paintComponent suggestion copeg made. I think thats how we did it when I learned it last year.
    Last edited by aussiemcgr; July 19th, 2010 at 02:49 PM.

  18. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Asido (July 19th, 2010)

  19. #14
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: problem with drawing images on JPanel

    Well, thanks all you guys for the help and tips. Everything works fine and moving on with the creation.

    By the way, speaking about JFrames container in Snake class, my way works fine as well:
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(new Board(), BorderLayout.CENTER);

    EDIT: If anyone is interested in the result (but I guess not ), here is the code:
    I used 3 images 10x10 for the apple, head and body.
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Image;
    import java.awt.Font;
    import java.awt.Toolkit;
    import java.awt.FontMetrics;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.ImageIcon;
     
    import java.util.Random;
     
    class Snake extends JFrame {
    	Snake(String title) {
    		setTitle(title);
    		setSize(310, 335);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setVisible(true);
     
    		Board b = new Board();
    		Container c = getContentPane();
    		c.setLayout(new BorderLayout());
    		c.add(b, BorderLayout.CENTER);
    //		Board b = new Board();
    //		b.setLayout(new BorderLayout());
    //		setContentPane(b);
    	}
     
    	public static void main(String args[ ]) {
    		new Snake("Snake game 2010 by Asido (c)");
    	}
    }
     
    class Board extends JPanel implements ActionListener {
    	private final int WIDTH = 302;
    	private final int HEIGHT = 309;
    	private final int DOT_SIZE = 10;
    	private final int ALL_DOTS_X = 30;
    	private final int ALL_DOTS_Y = 30;
     
    	private int x[ ] = new int[ALL_DOTS_X];
    	private int y[ ] = new int[ALL_DOTS_Y];
    	private int prevX[ ] = new int[ALL_DOTS_X * ALL_DOTS_Y];
    	private int prevY[ ] = new int[ALL_DOTS_X * ALL_DOTS_Y];
    	private int headX;
    	private int headY;
    	private int bodyX;
    	private int bodyY;
    	private int appleX;
    	private int appleY;
    	private int bodySize = 3;
    	private int delay = 300;
    	private int pausedDelay = 0;
    	int score = 0;
     
    	private boolean inGame = false;
    	private boolean left = true;
    	private boolean up = false;
    	private boolean right = false;
    	private boolean down = false;
    	private boolean appleStatus = false;
     
    	private Graphics g;
    	private Font hugeFont = new Font("Luxi Mono", Font.BOLD, 30);
    	private Font largeFont = new Font("Luxi Mono", Font.BOLD, 24);
    	private Font smallFont = new Font("Luxi Mono", Font.PLAIN, 14);
    	private Font tinyFont = new Font("Luxi Mono", Font.BOLD, 10);
    	private Random random = new Random();
    	private Timer timer;
    	private Image apple;
    	private Image head;
    	private Image body;
     
    	private Color backgroundColor = Color.BLACK;
    	private Color stringColor = Color.WHITE;
     
    	private MovementHandler movementHandler = new MovementHandler();
    	private RestartHandler restartHandler = new RestartHandler();
     
    	Board() {    	
    		setSize(WIDTH, HEIGHT);
    		setBackground(backgroundColor);
    		setFocusable(true);//kad KeyEventai veiktu ant JPanel
     
    		// images
    		ImageIcon appleIcon = new ImageIcon(getClass().getResource("apple.png"));
    		apple = appleIcon.getImage();
    		ImageIcon headIcon = new ImageIcon(getClass().getResource("head.png"));
    		head = headIcon.getImage();
    		ImageIcon bodyIcon = new ImageIcon(getClass().getResource("body.png"));
    		body = bodyIcon.getImage();
     
    		timer = new Timer(delay, this);
            timer.start();
     
    		begining();
        }
     
        void locateApple() {
            appleX = x[random.nextInt(30)];
            appleY = y[random.nextInt(30)];
     
            for(int i = 0; i < bodySize; i++) {
            	if((appleX == prevX[i] && appleY == prevY[i]) || (appleX == headX && appleY == headY))
            		locateApple();
            }
        }
     
        void begining() {
        	inGame = true;
        	left = true;
        	right = false;
        	up = false;
        	down = false;
     
        	bodySize = 3;
        	score = 0;
     
        	addKeyListener(movementHandler);
     
        	for(int i = 0; i < (WIDTH / 10); i++)
    			x[i] = i * DOT_SIZE;
    		for(int i = 0; i < (HEIGHT / 10); i++)
    			y[i] = i * DOT_SIZE;
    		locateApple();
    		headX = x[((int)(ALL_DOTS_X / 2))];
    		headY = y[((int)(ALL_DOTS_Y / 2))];
     
    		for(int i = 0; i < bodySize; i++) {
    			prevX[i] = headX + i * DOT_SIZE;
    			prevY[i] = headY;
    		}
     
    		setTimerDelay(200);
        }
     
        void setTimerDelay(int delay) {
        	timer.setDelay(delay);
        }
     
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            if(inGame) {
                if(!appleStatus) {
                    g.drawImage(apple, appleX, appleY, this);
                }
     
                g.setColor(stringColor);
                g.setFont(tinyFont);
                g.drawString("Score: " + score, 5, (HEIGHT - 1));
                g.setColor(Color.DARK_GRAY);
                g.drawLine(0, (HEIGHT - 10), WIDTH, (HEIGHT - 10));
     
                g.drawImage(head, headX, headY, this);
                for(int i = 0; i < bodySize; i++) {
                    bodyX = prevX[i];
                    bodyY = prevY[i];
                    g.drawImage(body, bodyX, bodyY, this);
                }
     
                Toolkit.getDefaultToolkit().sync();
                g.dispose();
            }
            else 
            	gameOver(g);
        }
     
        void gameOver(Graphics g) {
        	String gameOverMessage = "Game Over";
        	String restartMessage = "Press 'R' to restart";
        	String scoreMessage = "Score: " + score;
     
        	inGame = false;
        	g.setFont(largeFont);
        	g.setColor(stringColor);
        	FontMetrics largeFM = g.getFontMetrics(largeFont);
        	g.drawString(gameOverMessage, ((WIDTH - largeFM.stringWidth(gameOverMessage)) / 2), (HEIGHT / 2));
     
        	removeKeyListener(movementHandler);
        	addKeyListener(restartHandler);
     
        	FontMetrics hugeFM = g.getFontMetrics(hugeFont);
        	g.setFont(hugeFont);
        	g.drawString(scoreMessage, ((WIDTH - hugeFM.stringWidth(scoreMessage)) / 2), (HEIGHT / 3 * 2));
        	g.setFont(smallFont);
        	g.drawString(restartMessage, 10, (HEIGHT - 20));
        }
     
        void restart() {
        	begining();
        	repaint();
     
        }
     
        void detectCollision() {
        	if(headX < 0 || headX > 290 || headY < 0 || headY > 290)
        		inGame = false;
        	if(bodySize > 3) {	
        		for(int i = 0; i < bodySize; i++) {
        			if(headX == prevX[i] && headY == prevY[i])
        				inGame = false;
        		}
        	}
        }
     
        void checkApple() {
        	if(appleX == headX && appleY == headY) {
        		bodySize++;
        		score += 100;
        		locateApple();
     
        		switch(bodySize) {
        			case 10: setTimerDelay(190); break;
        			case 15: setTimerDelay(170); break;
        			case 20: setTimerDelay(150); break;
        			case 25: setTimerDelay(140); break;
        			case 30: setTimerDelay(130); break;
        			case 35: setTimerDelay(120); break;
        		}
        	}
        }
     
        public void actionPerformed(ActionEvent event) {    	
        	for(int i = bodySize; i >= 0; i--) {
        		if(i > 0) {
        			prevX[i] = prevX[i-1];
        			prevY[i] = prevY[i-1];
        		}
        		else {
        			prevX[i] = headX;
        			prevY[i] = headY;
        		}
        	}
     
        	if(up)
            	headY -= DOT_SIZE;
        	if(down)
        		headY += DOT_SIZE;
        	if(left)
        		headX -= DOT_SIZE;
        	if(right)
        		headX += DOT_SIZE;
     
        	detectCollision();
        	checkApple();
        	repaint();
        }
     
        private class MovementHandler implements KeyListener {
        	public void keyPressed(KeyEvent event) {
        		int keycode = event.getKeyCode();
    			if(keycode == KeyEvent.VK_UP && !down) {
    				up = true;
    				right = false;
    				left = false;
    				down = false;
    			}
    			if(keycode == KeyEvent.VK_LEFT && !right) {
                   	left = true;
                   	right = false;
                   	up = false;
                   	down = false;
                }
                if(keycode == KeyEvent.VK_RIGHT && !left) {
                   	right = true;
                   	left = false;
                   	up = false;
                   	down = false;
                }
                if(keycode == KeyEvent.VK_DOWN && !up) {
                    down = true;
                    up = false;
                    right = false;
                    left = false;
                }
        	}
     
        	public void keyReleased(KeyEvent e) {}
        	public void keyTyped(KeyEvent e) {}
        }
     
        private class RestartHandler implements KeyListener {
        	public void keyPressed(KeyEvent event) {
        		int keycode = event.getKeyCode();
        		if(keycode == KeyEvent.VK_R)
        			restart();
        	}
     
        	public void keyReleased(KeyEvent e) {}
        	public void keyTyped(KeyEvent e) {}
        }
    }
    Last edited by Asido; July 19th, 2010 at 08:06 PM.

Similar Threads

  1. Images (read/write, drawing)
    By helloworld922 in forum File Input/Output Tutorials
    Replies: 1
    Last Post: September 5th, 2011, 09:11 AM
  2. Drawing
    By toxikbuni in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 02:43 PM
  3. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 01:36 AM
  4. Drawing image on JPanel from another frame
    By jeryslo in forum AWT / Java Swing
    Replies: 3
    Last Post: December 8th, 2009, 03:01 PM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM