What is the best way to determine what JRadioButton is selected?
问题 Currently I'm getting the selected button in this way, but I don't if this is the right/best method. MAybe there something more easy or object oriented than this. private int getFilterType(JRadioButton... buttons) { for (int i = 0, n = buttons.length; i < n; i++) { if (buttons[i].isSelected()) { return i + 1; } } return buttons.length + 1; } 回答1: I like using the ButtonGroup itself for this. i.e., import java.awt.GridLayout; import java.awt.event.ActionEvent; import javax.swing.*; public