Search code examples
javabuttongroup

Best way to add a method to an oracle-made java class


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