Logo not showing

R

RANG

Hi,

Am new to java.

In front page of my project, i'm trying to load an logo using the code
below. but it didnt show the img in applet. Pls. tell me whats wrong
in this

import java.awt.*;
import java.applet.*;
/*<applet CODE="image.class" width=500 height=200></applet>*/
public class image extends applet
{
public void init()
{
Image img;
img=getImage(getCodeBase(),"rabbit.gif");
}
public void paint(Graphics g)
{
g.drawImage(img,10,10,this);
}
}
Thanks
 
A

Andrew Thompson

RANG wrote:
....
Am new to java.

Those who are new to Java, are best off avoiding GUI'd
applications, and *especially* applets.
A good groups for people learning Java is comp.lang.java.help
...it didnt show the img in applet. ...
public class image extends applet
{

Please indent code using the usual conventions,
though it is best to replace 'tab' characters with
spaces before posting.
public void init()
{
Image img;
img=getImage(getCodeBase(),"rabbit.gif");

<http://java.sun.com/javase/6/docs//api/java/applet/Applet.html#getImage(java.net.URL
)>
"This method always returns immediately,
whether or not the image exists."

It might be..
1) the Image cannot be found, or ..
2) the Image has not loaded yet.

A simple debugging technique for the first,
is to print the URL that is formed by adding
the codebase to the name, and then trying a
'direct fetch' on that URL in a browser.

For the second one, a MediaTraker can be used..
<http://java.sun.com/javase/6/docs//api/java/awt/MediaTracker.html>

HTH

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
 
R

RANG

RANG wrote:

...


Those who are new to Java, are best off avoiding GUI'd
applications, and *especially* applets.
A good groups for people learning Java is comp.lang.java.help




Please indent code using the usual conventions,
though it is best to replace 'tab' characters with
spaces before posting.


<http://java.sun.com/javase/6/docs//api/java/applet/Applet.html#getIma...
)>
"This method always returns immediately,
whether or not the image exists."

It might be..
1) the Image cannot be found, or ..
2) the Image has not loaded yet.

A simple debugging technique for the first,
is to print the URL that is formed by adding
the codebase to the name, and then trying a
'direct fetch' on that URL in a browser.

For the second one, a MediaTraker can be used..
<http://java.sun.com/javase/6/docs//api/java/awt/MediaTracker.html>

HTH

Thanks for alot of technique andrews
 
A

Andrew Thompson

RANG wrote:
...
Thanks for alot of technique andrews

You're welcome, but we* are generally more interested in
hearing the results (e.g. "URL was correct, but MediaTracker
solved the problem"), and note that my name is Andrew,
rather than Andrews.

* This helps not just me, but anyone else on the
group to know if more help is required - it also helps
anybody that finds the thread later, to know what
worked, and what did not work.

Good luck with it, and please get back to us
with the progress.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top