Win a copy of Kotlin Cookbook this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

I am following this tutuorial and I can not access the pictures on my netbeans 8.2?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am following this tutuorial (https://medium.com/@ssaurel/learn-to-create-a-snake-game-in-java-c41e3e3b216e) and I can not access the pictures on my netbeans 8.2?
Ska-rmavbild-2019-12-31-kl.-16.30.01.png
[Thumbnail for Ska-rmavbild-2019-12-31-kl.-16.30.01.png]
 
Marshal
Posts: 67036
255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't open the tutorial. I hope they don't recommend you to sublass JPanel like that, nor to make it implement action listener. Otherwise I would suggest you find a different tutorial.
 
Sheriff
Posts: 6568
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't mix Swing with JavaFX like that.  I don't know if that's part of your problem.

Why do you have "banking" in your path to dot.png?  Try just
If that doesn't work, tell us if this is a Maven project, an Ant project, or something else (that is, what does this project use to build with?)
 
martin codey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://medium.com/@ssaurel/learn-to-create-a-snake-game-in-java-c41e3e3b216e
I hope the link works now. Yeah I maybe should find another tutorial.

I also have the same error even with the code you suggested.
Ska-rmavbild-2019-12-31-kl.-19.16.54.png
[Thumbnail for Ska-rmavbild-2019-12-31-kl.-19.16.54.png]
 
Ranch Foreman
Posts: 91
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When dealing with resources I always recommend absolute paths unless you know and control against wich root reletive paths are resolved.
As an example: When I try to dynamically load additional modules at runtime I first have to find where they are in the filesystem. To determine this path I can either specify it as absolute like user.home and go on from there relative (System.getProperty("user.home") always gives a path that can be passed to the File(String) constructor and will result in a useable, writeable and executeable folder) or can get the current directory my application is placed and use this as a base directory. Be aware that the second approach could end up in a directory the current user doesn't have the needed rights.
When you bundle resources along with your application they're available in the current context classpath. Then you should be fine to use relative paths to the root of the classpath. The resolving to an actual or virtual File is then handled by the VM.

Kris
 
Knute Snortum
Sheriff
Posts: 6568
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, try this:
 
martin codey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this error when I tried the code you gave me." Incompitable types image cannot be converted to ImageIcon".
 
Campbell Ritchie
Marshal
Posts: 67036
255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this constructor. TryBut I can never remember the right way to use images in Swing. There should be something useful in this “trail” of the Java™ Tutorials.

[edit]Somebody pointed out a little mistake I made in that code. Corrected.
 
martin codey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much!
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!