• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Standalone app worked... as Applet does not.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a small game of memory cards which I got working properly, but I want to put on the web. I followed the basic guidelines, changed the constructor to init(), removed SetSize and SetTitles, removed references to closeWindow or system.exit(0), and thought that should be enough, but it does not work. After uploading to the server, it will not load and appears to give an access denied/file permission IIO error. (http://homepage.mac.com/aparentdesign/design/code.html)

All class files are in thee same directory as the HTML. I am worried it is not accessing the images in their folders, even though they also are in the same directory as the HTML and the relative link path should be the same no matter where it is. I am able to view the graphics as a URL, so I don't think it's .mac preventing access to the images. (http://homepage.mac.com/aparentdesign/design/random/0.jpg )

My other thought is that it does not like the timer method I used to pause the game?

Is there anything else that JApplets don't like? I've been searching Sun's tutorials and haven't found anything that seems to address this.

Since I don't know where exactly the problem may lie, I'm gonna have to paste the whole thing... sorry!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing I see right off the bat is the ImageIcon constructor calls: you're using the constructor that tries to use a local file path. This isn't going to work because when the applet runs on a desktop, the images aren't on the local machine; they're on the server. You can instead use the ImageIcon constructor that takes a URL for an argument. You can get the base URL by calling getDocumentURL() in the applet, and then build up the full URLs relative to that.
 
A Parent
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for responding!

I thougth I didn't need to use URLs, since the relative links are the same, they are in the same directory on server. (If this were html, it would have no difficulty accessing the images). Also, if I attempt to run this locally (off a browser, just dragging the html file to the browser) it doesn't render either, and that is local, and relative.

researching further tho, thanks for the lead.

[edit]

ok, I searched on URLs, searched on getDocumentURL, and hulkSmashed some code together, which still doesn't work. I am testing this locally from my hard drive, but as an applet in aHTML. It compiles, but displays this error onscreen:

Java Security AccesControlException: AccessDenied (java io FilePermission incredi/backgroundWin.jpg read) which is the first image that is attempted to access.
[ May 20, 2005: Message edited by: A Parent ]
 
A Parent
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the relevant code I added, and I changed all references to folder1/folder2 to be the URLS.

 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suggestions —
1 — allow java to do the heavy lifting for you
Ernest's suggestion

another possibility

this one will fetch images from a jar file and works for both an applet context and as an app, ie when you run the applet from a main method. For more about this see the How to Use Icons page in the tutorial.

2 — you only need to load the images into the applet one time.
 
A Parent
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks craig... the first hint helped a lot, and now the applet will run on the web. However, now I'm seeing other errors. The first time the game is played, all is well,... but the second time, when a match is found, it's resetting to the values the cards had in the first game.

So I'm guessing my reset method needs some kind of clear cache? I searched for a clear cache method but didn't find anything.

We didn't go over jar files in class at all, so I'm unfamiliar with them... and not sure how you mean that I only need to load the images once? There are more images than the game needs, so each time the game is played it needs to load the ones it wants that time?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can load the images into the applet at startup and store them in an array. Then in your reset method, instead
of loading in the images all over again for the new icons (easy on your hard drive but takes more bandwidth/time
over the network) you can get them from the array

[ June 02, 2005: Message edited by: Craig Wood ]
 
A Parent
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, that does seem much simpler. ::scampers off to edit code::

do you think that would solve my cache issue?
 
A Parent
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
huh. I had a reply here, and now it's gone.

anyway, I'm still working on making the code change you suggested--but am not sure if that would effect the cache issue?

btw, this is no longer a "school project" but is now on my own time and curiosity.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic