aspose file tools*
The moose likes Applets and the fly likes JApplet + JPanel + image.jpg Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "JApplet + JPanel + image.jpg" Watch "JApplet + JPanel + image.jpg" New topic
Author

JApplet + JPanel + image.jpg

Marcin Dabrowski
Greenhorn

Joined: Apr 24, 2009
Posts: 5

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?

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Apr 24, 2009
Posts: 5

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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 24, 2009
Posts: 5

Could you show me this on my example?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Line 47.
Marcin Dabrowski
Greenhorn

Joined: Apr 24, 2009
Posts: 5



Was what I needed. Thank you ;)
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Marcin Dabrowski wrote:Was what I needed. Thank you ;)


You're quite welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JApplet + JPanel + image.jpg