File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting Image From A Jar File

 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Pals,
I followed the tutorial provided in JavaWorld to to Extract an Image from a JAR File
But in the middle, I am in problem.

I am seeing the button in the north with image, but the center button is without image and the canvas is totally not displayed. I am expecting the center "Hello" button display an imageicon. My comannd line displays the following
jarTest.JarResources@784386 --- ashik 1 and
sun.awt.windows.WImage@171afc --- ashik 2
Waiting for your response on where did I miss?
:roll:
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got your code to work with some small modifications... I'm not sure why your second image isn't displaying. Is there anything special about the images you are trying to display? All the images I displayed from the JAR file displayed correctly... make sure file names are correct, and that the image isn't corrupted.

As far as why the canvas isn't showing up... the default size of a Canvas is 0x0, so just change it to something large enough to display the image in the constructor. (Also, it's a bad idea to mix AWT components like Canvas with Swing components... you will run into problems down the road...)
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Nate,
I am also where I am mistaking...Would you like to mail me your .java file and the .class file at azaman75@yahoo.com? I would be very pleased to you...
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing I changed in the JAR reading part were the names of the images and the JAR file...

But I'll go ahead and post the code I have now...

 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate, thank you very much. Your code is running in my machine. Now I'll find out where did I make the mistake and let you know.
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate, thank you very much. Your code is running in my machine. Now I'll find out where did I make the mistake and let you know.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic