• Post Reply Bookmark Topic Watch Topic
  • New Topic

Buttons not working  RSS feed

 
Jay Chakraborty
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks!!!
I think I need to go to basics before I move forward.........
Thank you once again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!