Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By pj6444
  • 1 Post By camickr

Thread: In jar execution I can't see My picture

  1. #1
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default In jar execution I can't see My picture

    Hello
    I create a program in NetBeans when I run it It works properly and shows my photo but in when I execute jar file (final app) I can't see my photo
    The whole project is in zip file with photo

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    /**
     *
     * @author  Mohsen 
     */
    public class MyPanel extends JPanel {
        private static final long serialVersionUID = 1L;
    
        @Override
        public void paintComponent(Graphics g){
            
            g.fillRect(0, 0, 200, 300);
            int red = (int)(Math.random()*255);
            int green = (int)(Math.random()*255);
            int blue =(int)(Math.random()*255);
            Color color =new Color(red, green, blue);
            g.setColor(color);
            g.fillOval(70, 70, 100, 100);
            Image image = new ImageIcon("netbeans.png").getImage();
            g.drawImage(image, 10, 20, this);
            
        }
       
        
    }
    Attached Files Attached Files
    Last edited by mohsen.noor; 01-04-2014 at 08:03 PM.

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    162
    Rep Power
    2

    Default Re: In jar execution I can't see My picture

    I would suggest that that you put your resources in the build path and load them like this.

    Java Code:
    try {
        BufferedImage image = ImageIO.read(getClass().getResource("/netbeans.png"));
    } catch(IOException e) {
        e.printStackTrace();
    }
    mohsen.noor likes this.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default Re: In jar execution I can't see My picture

    Also, don't do file I/O in the paintComponent() method. All images should be read in the constructor of the class or passed to the class.
    mohsen.noor likes this.

  4. #4
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    18
    Rep Power
    0

    Default Re: In jar execution I can't see My picture

    @pj6444
    @camickr
    Thanks

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2012, 04:44 PM
  2. Replies: 6
    Last Post: 11-30-2011, 08:39 PM
  3. Getting a picture out of a jar?
    By Zman3359 in forum New To Java
    Replies: 4
    Last Post: 02-02-2011, 11:55 PM
  4. Replies: 10
    Last Post: 11-29-2010, 02:02 PM
  5. Picture help
    By deathnote11 in forum AWT / Swing
    Replies: 13
    Last Post: 06-03-2008, 05:46 PM

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
  •