• Post Reply Bookmark Topic Watch Topic
  • New Topic

re-using radio buttons

 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writting an app that uses a set of radio buttons repeatedly on different screens. Not too difficult to repeat the code but it doesn't seem like the best approach. I was thinking of creating a class with the buttons, buttonGroup, JPanel and border all in one. But how would I handle the actionListener?

ms
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking of creating a class with the buttons, buttonGroup, JPanel and border all in one


Sounds like an excellent idea. Your new class can have methods such as,



or if you wanted to add one action listener to all radio buttons, you could



etc...
HTH D.
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or:

-----------------
jRadioButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// TODO: Add any handling code here
}
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot guys. Fairly obvious once you point it out like that, but I never would have thought of it myself.

ms
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!