• 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

Buttons not working

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,
This is my first posting to Java Ranch.
I am trying to learn Java GUI.
This is my code.

Nothing happens when I click on the buttons.
Thank you
Jay
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jay,
Welcome to JavaRanch!
Your problem is that you've got two different copies of the variables "exitButton" and "picture." One set are member variables; the only place these are used is in the actionPerformed() method. The other set are local to the PhotoAlbumApp constructor; these are the ones that point to the actual buttons. So when the ActionListener asks if the source of the event is the member variable exitButton, which is null, the answer is no, so the code doesn't run.
To fix this, you'll want to change the two lines

to look like

Then you're not declaring new local variables that hide the members anymore; you're just using the members.
If this doesn't make sense, then you need to back up a little and learn more about the Java language before you try to write this program; check out Sun's Java Tutorial, especially the first four sections.
 
Jay Chakraborty
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!!
I think I need to go to basics before I move forward.........
Thank you once again
 
Hey! You're stepping on my hand! Help me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic