This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I have been going through GUI/swing related topics from Head First Java. Based on those, I have tried the following small test program
The GUI comes up fine and I am able to click on the button widget added. However, in the actionPerformed() method, the print statements are working fine.
Trying to perform anything on button is giving me a nullpointerException. Since MyButtonListener is an inner class, I should be able to access both frame and button, right?
I am little confused as to why button is null here. Any help is much appreciated.
Inner classes aren't cool (in this case). Inner methods are
I cleaned your code up. I tested this and it works :
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)