Create a subclass that contains your new method.
Inheritance: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
Question
I have created a method for getting the text from a selected radio button when I pass it the buttongroup it's in. I've been reading that helper/utility classes might not be the best idea because they can turn into god classes, which I can see happening after a while. Plus, I'm only adding one method and that method is very specific to buttons.
So my question is, is there a best way to add a method to a class that oracle made? I would like this method to always be available whenever I make a new project and use buttongroups.
Solution
Create a subclass that contains your new method.
Inheritance: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
OTHER TIPS
Do you mean that you want to add methods to JRadioButton
? You cannot do that. The typical way this is done is by extending JRadioButton
, add the method and use that class everywhere.