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 3 of 3

Thread: Two questions: setting an image icon and closing up a game

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Two questions: setting an image icon and closing up a game

    Hi guys!
    I recently made a game. (really corny!)
    But, I want to package it and give it to my friends
    I know that I can create a jar of it and add the images to the folder, but what I would absolutely love is for it to just be a picture with the game name and click to run. Does anyone know how to do that? The second thing I would love is to replace that java icon to an icon of my preference, which I have been told numerous times to do with
    frame.setIconImage(Image image)
    which does not work for me.

    Thanks for any and all help


  2. #2
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: Two questions: setting an image icon and closing up a game

    Not sure what you mean on the first one. You can either do a picture that can be clicked as a JButton that has an icon as its content or you can have a JLabel that has an icon as a content and that uses a MouseListener to respond when clicked. On the second one, I'd need to see your code to see what's going wrong.

    Likely you need to specify the right directory and you didn't do it properly.

    If you're referring to the current directory, you should do.

    ./pictureFileName as your setup for the icon file name.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Two questions: setting an image icon and closing up a game

    Quote Originally Posted by MW130 View Post
    frame.setIconImage(Image image)
    which does not work for me.
    First, explain (or post) the code you use to load the image. Many times the image loading code is not much appropriate (and I always have a suspect about this ....).

    Second, setIconImage sets only one Image. Unfortunately, the O.S. can show the icon in several locations and in different sizes (e.g. small in the window title bar, larger in the system task bar, etc...). For this reason, since Java 6 is available the method (in any Window subclass):

    public void setIconImages(List<? extends Image> icons)

    to set more icons in different sizes.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. [SOLVED] Display icon/image in a JTable when reading in from MySQL
    By Psyclone625 in forum AWT / Java Swing
    Replies: 4
    Last Post: December 6th, 2013, 12:12 PM
  2. setting image to panel
    By godlynom in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 31st, 2012, 08:44 AM
  3. Replies: 0
    Last Post: February 14th, 2011, 06:10 AM
  4. Stupid thing can't find image icon right in front of it!!!
    By javapenguin in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 9th, 2010, 01:02 AM
  5. Setting up the Floor for 2d JAva Game?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 1
    Last Post: January 19th, 2010, 06:36 AM