Displaying pictures in Java
Here's the partial code:
The image can either be a 'gif' or a 'jpg'. You use MediaTracker to make sure the image has loaded before trying to display it. The paint() method will be called somewhat regularly and this is where you paint your image.
PS. You should check out The Java Tutorial. It is one of the most comprehensive tutorials I have ever seen and its free. I also includes this information that you are looking for. You can do it online, or you can download it and use it at your convenience. I would also recommend downloading the Java Platform docs. This will be a good reference, once you finish the tutorial.
---
Make it work.
Make it right.
Make it fast.
Edited by - CaptainJester on December 12, 2001 2:18:20 PM
public class Mine extends Applet { Image in; public void init() { //load image from applets directory through the URL in=loadImage(getDocumentSource()+"myimage.gif") //put the image into mediatracker MediaTracker t=new MediaTracker(this); t.addImage(in,1); try { t.waitForAll(); } catch (InterruptedException e) { System.out.println("error "+e); }}public void paint(Graphics g) { g.drawImage(in,0,0,this);}}
The image can either be a 'gif' or a 'jpg'. You use MediaTracker to make sure the image has loaded before trying to display it. The paint() method will be called somewhat regularly and this is where you paint your image.
PS. You should check out The Java Tutorial. It is one of the most comprehensive tutorials I have ever seen and its free. I also includes this information that you are looking for. You can do it online, or you can download it and use it at your convenience. I would also recommend downloading the Java Platform docs. This will be a good reference, once you finish the tutorial.
---
Make it work.
Make it right.
Make it fast.
Edited by - CaptainJester on December 12, 2001 2:18:20 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement