• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What am I doing wrong here?

 
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have just started playing around with Java canvas class to draw graphics but I cant figure out why I cant't draw an image from file. I have looked on a good few sites now and they all say the same thing; I have done what they ask, it just aint working. I want to program my own clock and am using a jpeg image of a handless clock for the background. ill just move the arms programmatically. Heres my canvas class:



In my gui window class I simply add this canvas component to the frame (jpanel works too) and the line, rect, etc draw fine as a test. The image doesn't though. What am I doing wrong?? Any help would be appreciated. its more than likely something stupid!

edit: when I print out the draw method to the console (System.out.println(g.drawImage(img1, 10, 10, this));) it returns false. API tells me something about the image not loading... if that helps.

Thanks.

I got it. Java doesn't recognise the "jpeg" extension, recognises "jpg". Lesson learned!!

[Edit - added code tags - MAB]
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm thats strange. the other day i changed a .jpg to a .txt just to see if ImageIO could still read it, and it did. i guess its because i got my image in a different way using JFileChooser and ImageIO.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i be the one to say "please use a meaningful subject line, of course something is going wrong or you wouldn't be here"
 
reply
    Bookmark Topic Watch Topic
  • New Topic