• 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

GUI ~ Image not showing up

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My image isn't showing up as a label on my GUI business. Do I have something in my code overriding it? Did I code it wrong? My other program with an image as a label works fine. I have verified that I'm using the correct file, and file extension, and that it is in the correct location. As far as research is concerned, I've been reading about ImageIcon to see if there is anything that clashes with it, as all the book does is skim (at best) over graphics in GUI's. Am I even looking in the right place? Thanks in advance for any help/advice you can offer.



[Edit - added code tags - see UseCodeTags for details]
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid you will have to provide more details. Where is the image file? Can you load it? Which component is it supposed to be displayed on? Have you used print statements to get debugging information?
I had to edit your code because it has long lines in, which are too wide for a screen.

All sorts of things about your code, I am afraid.
  • 1: Even without reading all your code, I think you have a God class. One that is almighty and tries to do everything. Not usually a good idea at all.
  • 2: You have all sorts of local variables in the main method which appears never to be used; they simply go out of scope.
  • 3: You have lots of fields in the recipe class. I suspect most of them can be local variables in the code which sets up the GUI.
  • 4: Another thing you see in some books, addActionListener(this). That is liable to lead to awkward, non-object-oriented programming. Create your listeners as separate classes.
  • 5: You are using the == operator on reference types (== "Tacos"). That is very unreliable; you should use an equal...() method.
  • I am pleased to see you are not making your principal class extend frame or similar, and that you are using invokeLater.

    I think this discussion would fit better in our GUIs forum, so shall move it.
     
    Debby Miller
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks! I'm super new (obviously). You bring up some really great points. I'll work on the stuff you pointed out first, and then come back if my question is still relevant. BTW this place is awesome!
     
    Campbell Ritchie
    Marshal
    Posts: 79151
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You’re welcome
    How have you got on with it?
     
    Debby Miller
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, what happened was I wrote the program at home implementing new stuff I learned at school, so every time I learned something (i.e. if-else statements) I would add it to the program. The problem with that is when I learned about using swing and GUI business I didn't know what to do with the rest of my code. So I just commented it out for now, which is why I had all those extra variables. As far as the God class problem is concerned, I've been thinking about how to break it down into separate classes and methods, but not sure where to start. I changed all the == to .equals, thank you for the heads up. I'm trying to figure out how to create my listeners as separate classes, but to do that I think I need to really understand what a listener is first. My book has a paragraph on it, so I think I need to read more on the internet. This place is soo much nicer than the other forum I was introduced to, thanks again for all your help.

    ~Debby
     
    reply
      Bookmark Topic Watch Topic
    • New Topic