문제

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.

도움이 되었습니까?

해결책

Create a subclass that contains your new method.

Inheritance: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top