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: Does anyone know how to display an image from a file on your screen?

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Does anyone know how to display an image from a file on your screen?

    I am making a game and am tired of jsut using shapes such as rectangles and other things. Does anyone know how to put in your own files as images onto a JFrame? If you do then please teach me how to set it up and what parameters it takes and other things I need to know about it. Here is what I have done so far but it didn't work.
    package galaga;
     
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.ImageObserver;
     
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class HELPME extends JFrame {
    	ImageIcon worthless = new ImageIcon("CRAPPYSPACESHIP.png");
    	Image SHIP = worthless.getImage();
     
    	JFrame HELPME = new JFrame();
    	JPanel bob = new JPanel();
     
    	public HELPME() {
    			super("Title");
    			setVisible(true);
    			setSize(400, 400);
     
    	}
    	public void paint(Graphics g) {
     
    		g.drawImage(SHIP, 100, 200, 50, 90, ImageObserver );
    	}
     
    }

    I wrote ImageObserver because I don't know what it is. If anyone tries to help me it will be much appreciated!
    Last edited by mkrage; October 25th, 2012 at 09:51 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Does anyone know how to display an image from a file on your screen?

    Is this the same question as your other post? http://www.javaprogrammingforums.com...wont-work.html

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Does anyone know how to display an image from a file on your screen?

    No this is just displaying an image the other one is makeing it move and displaying it

Similar Threads

  1. Radio button .. display empty screen ?? plz Help
    By smasm in forum AWT / Java Swing
    Replies: 4
    Last Post: April 7th, 2012, 07:21 PM
  2. Image Doesn't Display with Qualified Image Path????
    By swaginator in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 31st, 2012, 12:29 AM
  3. Display patterns on the screen
    By finjws in forum Loops & Control Statements
    Replies: 12
    Last Post: February 10th, 2012, 01:11 PM
  4. [SOLVED] Display longest string on screen
    By mwardjava92 in forum Object Oriented Programming
    Replies: 1
    Last Post: January 29th, 2012, 12:12 PM
  5. Showing an Image on screen
    By doobybug in forum AWT / Java Swing
    Replies: 1
    Last Post: May 10th, 2011, 07:49 AM