Results 1 to 11 of 11
  1. #1
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Inserting Image in a Program

    Hi i am in std 10
    i wanted to learn how i could insert an image in java
    i'm quiet new to this language but i've got a project in which i have to make a something for a travelling agency
    i feel that the program would be pretty bland without any images so i wanted to learn a way to add images

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,518
    Rep Power
    5

    Default Re: Inserting Image in a Program

    Add images to what?

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    8

    Default Re: Inserting Image in a Program

    You are welcome to Java-forums.

    Btw you did not mention what type of application you are developing on.

    You might have forgot to mention it.
    Mak
    (Living @ Virtual World)

  4. #4
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: Inserting Image in a Program

    i did it like this:
    Java Code:
    ImageIcon img = new ImageIcon("C:\\Users\\Home\\Desktop\\lol.png");
    	b1.setIcon(img);
    so basically, b1 is my button, so i put an image in my button, but if you want to put in in your JFrame you just enter the frame name instead of b1.

    Java Code:
    ImageIcon img = new ImageIcon("C:\\Users\\Home\\Desktop\\lol.png");
    and in this imageicon thin you enter the path where your picture is located

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,299
    Blog Entries
    7
    Rep Power
    24

    Default Re: Inserting Image in a Program

    Quote Originally Posted by MR bruto View Post
    i did it like this:
    Java Code:
    ImageIcon img = new ImageIcon("C:\\Users\\Home\\Desktop\\lol.png");
    	b1.setIcon(img);
    so basically, b1 is my button, so i put an image in my button, but if you want to put in in your JFrame you just enter the frame name instead of b1.
    Don't give incorrect advice; read the API documentation for the JFrame class and its content pane.

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  6. #6
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Re: Inserting Image in a Program

    i wanted to insert it only in a simple java program
    i mean public void main( ){
    //insert image

    System.out.println(".......");

    }

  7. #7
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Re: Inserting Image in a Program

    Just a general program u know the simple one

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

    Default Re: Inserting Image in a Program

    You can only add an Icon to a (visual) component that knows how to handle it (e.g. a JLabel or JButton), or you can draw an Image in any component that can be visualized (basically all Components, JComponents and descendants).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  9. #9
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Re: Inserting Image in a Program

    Quote Originally Posted by JosAH View Post
    You can only add an Icon to a (visual) component that knows how to handle it (e.g. a JLabel or JButton), or you can draw an Image in any component that can be visualized (basically all Components, JComponents and descendants).

    kind regards,

    Jos
    thanks for the suggestion but i totally didnt get what u are trying to say i mean
    ive just learnt the basics of java
    nothing more so i totally dont know which class JPanel is included in and how i would draw an image in a ny component

    --Damian

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

    Default Re: Inserting Image in a Program

    Quote Originally Posted by damian View Post
    thanks for the suggestion but i totally didnt get what u are trying to say i mean
    ive just learnt the basics of java
    nothing more so i totally dont know which class JPanel is included in and how i would draw an image in a ny component
    Basically you can't say "hey, program, I've got an image here; do something with it! Nothing complicated please". Study the Swing tutorial so that you at least understand what I was talking about.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  11. #11
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

Similar Threads

  1. program inserting a polygon
    By femyan21 in forum New To Java
    Replies: 4
    Last Post: 03-22-2011, 01:57 AM
  2. Replies: 6
    Last Post: 07-21-2010, 06:15 AM
  3. Inserting image into RTF file using pure JSP
    By joseluisbz in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 01-05-2010, 07:17 PM
  4. Opening an image in Photoshop from a Java program
    By orion_mcl in forum Advanced Java
    Replies: 10
    Last Post: 10-25-2009, 03:04 PM
  5. Putting image into program
    By SprayAndPray69 in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 04:38 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
  •