This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ActionListener on Radio buttons - newbie help  RSS feed

 
Mark Dittrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've just started writing my first "by myself" app, having followed alot of examples in the book I've been reading (Head First Java).

All I'm trying to do is make a simple "quiz" - i ask a question in a label, give some radio boxes (in a button group) for you to select the correct answer, and then tell you if the answer is right or not. I seem to be almost there, but I'm struggling with the ActionEvent code. . I keep getting told in my actionPerformed method that it cant resolve my checkbox (Q1A4) and i have no idea why. Below is the code. If anyone could assist or point me in the right direction I'd be very appreciative.


 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1A4 is a "local variable" defined on the go() method. So only code in the go() method can access it.

If you want to access the variable from another method then you need to define it as an "instance variable", the way you did with the "result" label.
 
Mark Dittrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob. Ridiculously simple, but it works now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!