Results 1 to 10 of 10
  1. #1
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default am i doing this right?

    is it my code right?

    XML Code:
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    
    public class Image {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException {
            
            System.out.println(System.getProperty("user.dir"));
            File file = new File("sign.jpg");
            BufferedImage img;
            img = ImageIO.read(file);
    
            // TODO code application logic here
        }
    }
    but why the image cannot open?

  2. #2
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: am i doing this right?

    I'm not expirienced with image and files but I you didn't created a new img object.

  3. #3
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: am i doing this right?

    i already create an image named sign.jpg by using paint, but when i run this program, the image cannot open.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default Re: am i doing this right?

    Your program prints out a directory (its cwd (current working directory)) Can you find the file sign.jpg in that directory?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: am i doing this right?

    why the image cannot open?
    What do you mean by "open"? There is nothing in that code to actually display the image.

  6. #6
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: am i doing this right?

    how to display the image?

  7. #7
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: am i doing this right?

    if i put the image in the netbeanproject, in folder name image. should i write netbeanproject.dir?

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default Re: am i doing this right?

    Quote Originally Posted by aelynne View Post
    if i put the image in the netbeanproject, in folder name image. should i write netbeanproject.dir?
    You don't really know what you're doing, do you? The directory where the program runs is displayed by the program itself (user.dir); that's the directory where your image file is supposed to be stored. An alternative is to define the absolute path for the File object, e.g. new File(C:/usr/whatever/image/sign.jpg");

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: am i doing this right?

    okay, im done with it, now, how to display the image? what type of coding should i use?

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default Re: am i doing this right?

    Quote Originally Posted by aelynne View Post
    okay, im done with it, now, how to display the image? what type of coding should i use?
    Can you read the image now? It's time to study the Swing framework: you have to create a JWindow or JFrame or JDialog, add a subclass of a JPanel to it and make the overridden paintComponent(Graphics g) method draw your image; alternatively you can create a label and add an ImageIcon to it that contains your image. This all sounds like voodoo to you now, so you'd better start reading the Swing tutorial first. There is no special 'type of coding' you can stea^H^H^H^Huse.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

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