Re: Question regarding Japplets inside a webpage?
Shraff wrote:
I have a java applet that scrolls through some pictures that are found
in the same directory as the java code. When I run the applet from
inside of my compiler everything seems to work fine. However, when I
insert the applet into html code using the applet tag or the object
tag it dosent seem to work. The applet will appear and the buttons
will be there but when the start button is pressed it will not scroll
the pictures. I am new to adding applets to the web and am not sure
what my problem is.. any help would be greatly appreciated. Here is
the code I am using.
public void fillIconArray()
{
numberofPics = 9;
pics = new ImageIcon[9];
thumbs = new ImageIcon[9];
String fileNames, extension;
extension = ".jpg";
for(int x=0; x< numberofPics; x++)
{
fileNames = "";
fileNames = Integer.toString(x);
fileNames = fileNames + extension;
pics[x] = new ImageIcon(fileNames);
thumbs[x] = new
ImageIcon(pics[x].getImage().getScaledInstance(427, 341,
Image.SCALE_FAST));
System.out.println(fileNames);
What do you mean, in the context of an applet, by "in the same directory as the
java code"? Do you mean as separate files in the web server filesystem, or as
files within the applet's jar? Unfortunately in neither case can you use a
simple filename as you have in the above code. Also, a simple applet is unable
to load files from your local filesystem.
In the former case you need to construct a proper URL to the image file so it
can be requested from the web server. In the latter case you should use
ImageIcon(getClass().getResource(fileNames)) to locate the image file in the
jar. For more info. look at
http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html and also
Google "applet load image".
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555