多個JRadioButton 加入ButtonGroup之后,如何獲取某個選定的JRadioButton 的值。我試過好多辦法都不行,以下是部分代碼:????????????????JRadioButton rbtnUser = new JRadioButton("普通用戶",true); //default select rbtnUser.setBounds(129, 175, 87, 23); contentPane.add(rbtnUser); JRadioButton rbtnRoot = new JRadioButton("管理員"); rbtnRoot.setBounds(225, 175, 64, 23); contentPane.add(rbtnRoot); ButtonGroup bg=new ButtonGroup(); bg.add(rbtnUser); bg.add(rbtnRoot); if(rbtnUser.isSelected()){ userType=rbtnUser.getText(); }else if(rbtnRoot.isSelected()){ userType=rbtnRoot.getText(); }????????為什么每次只能獲得默認(rèn)選擇的“普通用戶”的值,另一個無法獲取。。。。。????????各路大神幫幫忙,趕著交作業(yè)呢。。。。。謝謝
添加回答
舉報
0/150
提交
取消