Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[newbie] addRadioButton(String buttonName, final Border b, JPanel whichPanel)  RSS feed

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are designing a class would you rather have?

a. A call to a function with "hard-coded" private variable names.

BorderFrame.java


b. Re-writing the method for to decrease coupling and allow for more flexibility



Are you aware of any performance (fine-tuning) issues that may favor the first method?
 
Campbell Ritchie
Sheriff
Posts: 55317
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not convinced I would use either.

Your method has a misleading name, since it doesn't show where or how it actually adds the RadioButton. What you wrote has no effect at all.

What you mean is a createRadioButtonToSetBorder method, which returns a JRadioButton reference, and you pass the title, the type of Border, and the Component (you would have to check, but probably a superclass of the panel) you wish to set the border on, as parameters. Your method can probably have public static modifiers. Remember to add RadioButtons both to their enclosing Component and to a ButtonGroup. I don't like the idea of a method which adds something to a field which is coded in the method.

This sort of thing is usually discussed in the Swing forum, so I shall move you. And please stop writing [newbie] on all your posts.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!