Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot get Image to load to Applet  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hey guys so im creating a clickable applet , that has an image that can move left , right , up and down etc. i'm having difficulty though getting the image to open with the applet. When i open the applet, it opens up but there is no image that loads up. I have the image cup.gif in the same folder as the cllass file but it just wont open . Any idea how to fix this problem?
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have attached the image
cup.gif
[Thumbnail for cup.gif]
cup.gif
 
Marshal
Posts: 58830
179
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using AWT Components and applets; AWT was regarded as obsolete last century and applets became obsolete more recently.
Avoid addActionListener(this) which can lead to bad code like in line 56. Use individual listener objects. I also suspect there is a serious error in line 66.
Don't use == on Strings.
Use Swing or JavaFX and have a look at this part of the Java™ Tutorials.
 
Saloon Keeper
Posts: 4417
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Describe the directory layout on the server, particularly where the HTML file, the class files and image file reside.

You might want to use a MediaTracker to monitor the loading of the image; see https://coderanch.com/wiki/660260/Code-Barn-Load-Gif and https://coderanch.com/wiki/660259/Code-Barn-Load-Gif-Msg for examples.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Why are you using AWT Components and applets; AWT was regarded as obsolete last century and applets became obsolete more recently.
Avoid addActionListener(this) which can lead to bad code like in line 56. Use individual listener objects. I also suspect there is a serious error in line 66.
Don't use == on Strings.
Use Swing or JavaFX and have a look at this part of the Java™ Tutorials.


The textbook that I'm using requires me to use AWT components and applets. It is outdated but the assignments require me to use these outdated tools
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Describe the directory layout on the server, particularly where the HTML file, the class files and image file reside.

You might want to use a MediaTracker to monitor the loading of the image; see https://coderanch.com/wiki/660260/Code-Barn-Load-Gif and https://coderanch.com/wiki/660259/Code-Barn-Load-Gif-Msg for examples.



The book im using requires me to use the getImage(getDocumentBase(), "cup.gif");

the code is fine the only issue i'm having is when i start up the applet there is no image. I just need the image to load on the applet and i will  be done.
 
Tim Moores
Saloon Keeper
Posts: 4417
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Describe the directory layout on the server, particularly where the HTML file, the class files and image file reside.



Yogi Permaul wrote:The book im using requires me to use the getImage(getDocumentBase(), "cup.gif");


? That's what that code uses.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:

Tim Moores wrote:Describe the directory layout on the server, particularly where the HTML file, the class files and image file reside.



Yogi Permaul wrote:The book im using requires me to use the getImage(getDocumentBase(), "cup.gif");


? That's what that code uses.



i've been trying to figure this out for two days now. I'm so confused , i dont even know anymore
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yogi Permaul wrote:

Tim Moores wrote:

Tim Moores wrote:Describe the directory layout on the server, particularly where the HTML file, the class files and image file reside.



Yogi Permaul wrote:The book im using requires me to use the getImage(getDocumentBase(), "cup.gif");


? That's what that code uses.



the HTML file , class and image file all reside within the C drive of my Pc.

 
Tim Moores
Saloon Keeper
Posts: 4417
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the HTML file , class and image file all reside within the C drive of my Pc.


Does that mean all in the same directory?

Are you accessing the files through a web server, or directly from the file system? I think that the latter should work, but I'm not certain. If you want to be certain, use a web server.

And Campbell is right - whoever makes you learn applets makes you waste your time learning obsolete stuff. You should think about changing classes, or challenging your teacher about this.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:

the HTML file , class and image file all reside within the C drive of my Pc.


Does that mean all in the same directory?

Are you accessing the files through a web server, or directly from the file system? I think that the latter should work, but I'm not certain. If you want to be certain, use a web server.

And Campbell is right - whoever makes you learn applets makes you waste your time learning obsolete stuff. You should think about changing classes, or challenging your teacher about this.



yes all in the same directory. I will be sure to mention that to my course coordinator. Thank you for your help i'm still a beginner to java and learning as i go along, any help is greatly appreciated.
 
Tim Moores
Saloon Keeper
Posts: 4417
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check if there are any error messages in the Java Console. On Windows, open the Java control panel to see that.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:You might want to check if there are any error messages in the Java Console. On Windows, open the Java control panel to see that.



Thank you i've managed to fix it :]
 
Campbell Ritchie
Marshal
Posts: 58830
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done Please show us what correction worked.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Well done Please show us what correction worked.



hahaha I simply got so frustrated I ended up just replacing the image with a new one and the program immediately started working
 
Campbell Ritchie
Marshal
Posts: 58830
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hahahahahahahahaha!
Unfortunately that doesn't teach you what the real problem was. Go back to the old image and work out the differences from the new image and see if you can find an explanation for your earlier problems.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Hahahahahahahahaha!
Unfortunately that doesn't teach you what the real problem was. Go back to the old image and work out the differences from the new image and see if you can find an explanation for your earlier problems.


I will do so sir thank you for your help and guidance.
 
Campbell Ritchie
Marshal
Posts: 58830
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yogi Permaul wrote:. . . thank you for your help and guidance.

That's a pleasure
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!