Click to See Complete Forum and Search --> : Problem with an applet


Berisades
November 19th, 2009, 10:01 AM
Hi,
I am building a little game and it works fine as an application but when I build it as an applet something strange happens. When I run the applet in Eclipse I don't see the whole applet but just a part of it. The missing part is image icons... Well, it's a bit more complicated: I have special class which extends Jlabel and on the labels I have image icons and status fields which can be of type int and are needed for easier implementation of my game. So I don't see exactly that objects of the extended JLabel class with images on it. When I create a HTML file and put the applet, I see just a gray rectangle and nothing else. In Eclipse I see at least the stuff that isn't of object of my label class. Any idea who it is so and how can I fix it?

Thanks!

dlorde
November 19th, 2009, 01:53 PM
Are you reading the images from disk? Applets run in a security 'sandbox', which means they are not permitted to read from or write to the client machine. Check the Java console for security exception messages.

See What Applets can and can't do (http://java.sun.com/docs/books/tutorial/deployment/applet/security.html), Applet Security (http://www.wutka.com/hackingjava/ch3.htm), etc. Google 'java applet security' for more.

Any programming problem can be solved by adding a level of indirection...
Anon.

Berisades
November 19th, 2009, 02:15 PM
I was reading them from the disc but after I tried to read them like this nothing happened and I see absolutely nothing now:

private static URL url;
private static Toolkit tk = Toolkit.getDefaultToolkit();
private static Image image;

private void setURL()
{
try{
url = new URL("http://img136.imageshack.us/img136/8159/something.jpg");
} catch (MalformedURLException VariableDeclarationID) {}
image = tk.getImage(url);
}

and then invoke the above method in the constructor.

How do I make it read it not from the disc and not from a website???

dlorde
November 19th, 2009, 02:55 PM
So what does the Java console say? Does it show any error messages?

Why do we never have time to do it right, but always have time to do it over?
Anon.

Berisades
November 19th, 2009, 02:59 PM
It doesn't say anything bad. Well, I figured out the problem - removed static from the URL. Now the problem is how to get the URL of my images and use them without uploading them separately on the Internet? And even one more problem: I see the applet in Eclipse but again, I don't see it in the browser.