Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get actionPerformed to return a value

 
Anudeep Pat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers, need some help.

I am creating a Multiple choice Questionnaire using Java Swings connected to MySql.

And am trying to get actionPerformed return the value selected from a Radio Buttongroup because I am trying to validate if the chosen value of the radio button is right.

I put the answer field from the database into a label(if that helps). I dont even know if this is the right way to do it.

Suggestions please!!!
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you seen the tutorial on Radio Buttons? http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#radiobutton.

The actionPerformed method is a void type, so it cannot return values. However, you can set program variables from within the actionPerformed method, so this should do what you want.

 
Anudeep Pat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that actionPerformed wouldnt return any value but I was wondering if there's a way around that.

Anyways, my concern here is that I want to compare the value selected from radio buttons against the one in the database!
 
Anudeep Pat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just got it, by declaring a String variable in the class and putting the answer into it and then sending it to the actionPerformed function where it can be compared to the selected value!!!

Here's the link that'll give you a rough idea!!!

http://forums.sun.com/thread.jspa?threadID=372477
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic