Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PLEASE HELP ME to put an image over a background image !!

843807May 22 2002 — edited May 25 2002
Hello,

I need help on my AWT program. I have a map being displayed, and would like an image of a car (car.gif) to be displayed over the image of the map.

So my question is: How do I make this map a background image, and put the picture of the car right over it. I need my map loaded all the time, and the picture of the car will be reloaded many times over the same map, so a class method to load this map would be perfect. Any help, code, or suggestions would be great. Thanks so much!

Here is what I currently have for my map.
import java.awt.*;
import java.awt.event.*;

public class MyImage extends Panel {
    private Image im = null;
    Graphics g;

    public void getMap(){

      im = Toolkit.getDefaultToolkit().getImage("C:\\test_map.gif"); 
	    MediaTracker tracker = new MediaTracker(this);
	    tracker.addImage(im,0);
	    try {
	        tracker.waitForID(0);
 	    }catch (InterruptedException e){}
	        repaint();
    }
    
   public void paint(Graphics g){
        this.g = g;
	    if (im != null)	{
            g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);  //706,397
        }
    } 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 22 2002
Added on May 22 2002
6 comments
77 views