Results 1 to 2 of 2
  1. #1
    Naxix is offline Member
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default Applet Import Image - How to?

    So, i'm pretty new to java, and i just jumped into applets. And image importing might function the same way whenever it's and applet or not, but i can't seem to get it right, i've searched, but i haven't found anything that worked, or it was too complicated for me to duplicate.

    So my question is, how do i import an image, the code i have so far gives no errors, but it's just blank.

    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.Image; // Tried import Image MyImage too, but gave an error.
    
    
    public class HelloWorld extends Applet
    {
    
    	private static final long serialVersionUID = 1L;
    
    		Image MyImage;
    
    		public void init()
    		{
    		  MyImage = getImage(getCodeBase(),"003.JPG"); 
    		}
    	public void paint (Graphics g)
    	  {
    		g.drawImage(MyImage,250,250,this);
    	  }
    }
    So could anyone explain or show how to import images, i would be greatful!

    Best Regards Naxix

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: Applet Import Image - How to?

    A better way of loading images is by using BufferedImages and loading them using ImageIO.read();
    Java Code:
    BufferedImage image;
    image = ImageIO.read(new File("filname");

Similar Threads

  1. Replies: 1
    Last Post: 07-28-2011, 08:48 AM
  2. Replies: 12
    Last Post: 04-14-2011, 01:58 PM
  3. Background Image of Applet
    By BangJava in forum Java Applets
    Replies: 8
    Last Post: 11-24-2010, 05:48 AM
  4. how to import packages files to my applet in netbean
    By funkygarzon in forum Java Applets
    Replies: 4
    Last Post: 08-16-2010, 07:02 PM
  5. how to import a picture into an applet
    By cecily in forum Java Applets
    Replies: 2
    Last Post: 01-15-2010, 08:51 PM

Posting Permissions

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