Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JApplet + JPanel + image.jpg

 
Greenhorn
Posts: 5
Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm currently making this simple gui tool and I want to use JApplet class. My plan is to use JApplet instead of JFrame class. Currently I've JPanel with image attached to it and I want to add this little thing to JApplet. Unfortunately I don't see image in JPanel. Something is definitely wrong. Image.jpg is in JPanel in case when I'm using JFrame but It's not working with JApplet. Does anybody know how to do this correctly?

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcin Dabrowski wrote:Hi,

I'm currently making this simple gui tool and I want to use JApplet class. My plan is to use JApplet instead of JFrame class. Currently I've JPanel with image attached to it and I want to add this little thing to JApplet. Unfortunately I don't see image in JPanel. Something is definitely wrong. Image.jpg is in JPanel in case when I'm using JFrame but It's not working with JApplet. Does anybody know how to do this correctly?



Are you adding your JPanel to the JApplet's contentPane? It's hard to know what you're doing wrong without code. My main suggestion for you is to create and post an SSCCE showing your problem. Please check out the SSCCE link to see how to make this application in such a way that we can help you more easily.

Best of luck!
 
Marshal
Posts: 28288
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed. Post your code. For all we know it might be that basic beginner error where you think a FIle object can be used to access a resource on the server where the applet was downloaded from.
 
Marcin Dabrowski
Greenhorn
Posts: 5
Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, guys,

Ok, perhaps you're right. Maybe I just making elementary mistakes in here. Who knows? Currently I'm doing something like this. Resource path to image is correct (I've checked it) and this image should be displayed in panel. One thing is funny. When I do the same with JFrame and just add the new Panel() everything works perfect.
 
pete stein
Bartender
Posts: 1561
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcin Dabrowski wrote:Ok, perhaps you're right. Maybe I just making elementary mistakes in here. Who knows?



Perhaps. You appear to be obtaining your image via the Toolkit's createImage(String filename) method, and I believe that this won't work with applets since for applets files don't exist (corrections most welcome here!). I'm no applet expert, but I've seen code work where the image is obtained using the ImageIO read(InputStream input) method that takes an InputStream for parameter and pass in the image as a resource via class's getResourceAsStream(String name) method. Note that the name passed into this last method is the resource relative to the class file location and so will usually not be the same String that you pass into the createImage method that you use.
 
Marcin Dabrowski
Greenhorn
Posts: 5
Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you show me this on my example?
 
Paul Clapham
Marshal
Posts: 28288
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 47.
 
Marcin Dabrowski
Greenhorn
Posts: 5
Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Was what I needed. Thank you ;)
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcin Dabrowski wrote:Was what I needed. Thank you ;)



You're quite welcome!
 
reply
    Bookmark Topic Watch Topic
  • New Topic