drawImage for Applet

Hi there,

I need two images to show for my "Horse Race" applet. I believe that I have everything lined up but the applet shows only my other shapes and not my two images. Is there anything that can be spotted in the code?

Thanksimport javax.swing.*;

import java.applet.*;

import java.awt.*;

/*

<applet code = "HorseRace.class" width = 800 height = 600>

</applet>

*/

publicclass HorseRaceextends Applet

{

Image image1;

Image image2;

publicvoid init()

{

JLabel label =new JLabel ("Horse Race Applet" , SwingConstants.LEFT);

add(label);

image1 = getImage ( getDocumentBase (),"Horse1.jpeg");

image2 = getImage (getDocumentBase(),"Horse2.jpeg");

}

publicvoid paint (Graphics g)

{

super.paint (g);

g.setColor(Color.GREEN);

g.fillRect(0,25,800, 400);

g.setColor(Color.YELLOW);

g.fillRect(0,100,800,50);

g.fillRect(0,300,800,50);

g.drawImage(image1, 0, 100,this);

g.drawImage(image2, 0, 300,this);

}

}

[1809 byte] By [poema] at [2007-10-2 3:58:14]
# 1

// <applet code="HorseRaceRx" width="800" height="600"></applet>

import java.applet.Applet;

import java.awt.*;

import javax.swing.*;

public class HorseRaceRx extends Applet

{

Image image1;

Image image2;

public void init()

{

JLabel label = new JLabel ("Horse Race Applet" , SwingConstants.LEFT);

add(label);

image1 = getImage ( getDocumentBase (), "Horse1.jpg");

image2 = getImage (getDocumentBase(),"Horse2.jpg");

// getImage returns immediately, ie, it doesn't wait for the image

// data to load. see MediaTracker api. to load the images:

MediaTracker mt = new MediaTracker(this);

mt.addImage(image1, 0); // 0 = highest loading priority

mt.addImage(image2, 0);

try

{

mt.waitForAll();

}

catch(InterruptedException ie)

{

System.err.println("interrupted: " + ie.getMessage());

}

}

public void paint (Graphics g)

{

super.paint (g);

g.setColor(Color.GREEN);

g.fillRect(0,25,800, 400);

g.setColor(Color.YELLOW);

g.fillRect(0,100,800,50);

g.fillRect(0,300,800,50);

g.drawImage(image1, 0, 100, this);

g.drawImage(image2, 0, 300, this);

}

}

74philipa at 2007-7-15 23:19:59 > top of Java-index,Desktop,Core GUI APIs...