-
applet
import java.awt.*;
import java.applet.*;
public class a extends Applet
{
Image q;
public void init()
{
q=getImage(getCodeBase(),"red.png");
}
public void paint(Graphics e)
{
e.drawImage(q,200,290,this);
}
}
i hav written this program but it is not showing any red image it is not showing any thing in applet how can i load the icon.png from a folder do i hav to set the class path if so how
-
Code:
// <applet code="LoadAndDraw" width="400" height="400"></applet>
import java.awt.*;
import java.applet.*;
public class LoadAndDraw extends Applet
{
Image q;
public void init()
{
String path = "images/hawk.jpg";
// Create image object.
q=getImage(getCodeBase(), path);
// Load the image data.
MediaTracker mt = new MediaTracker(this);
mt.addImage(q, 0);
try
{
mt.waitForID(0);
}
catch(InterruptedException e)
{
System.out.println(mt.statusAll(false));
}
}
public void paint(Graphics e)
{
e.drawImage(q, 50, 50, this);
}
}