GUI 好了,对了请问怎么让jRadioButton,在点击后回到未点击的状态呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 group.clearSelection();public class RadioButtonTest extends JFrame { JButton jbt = new JButton("重置"); JRadioButton[] jrbts = new JRadioButton[4]; ButtonGroup group; public RadioButtonTest(){ setTitle("RadioButtonTest"); setSize(400,200); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0); } }); JPanel buttonPanel = new JPanel(); group = new ButtonGroup(); for(int i = 0;i < jrbts.length ;i ++){ jrbts[i] = new JRadioButton(); addRadioButton(buttonPanel,group,"jrbts["+i+"]",false); } getContentPane().add(buttonPanel,"South"); jbt.addActionListener(new MyListener()); getContentPane().add(jbt,"Center"); } class MyListener implements ActionListener{ public void actionPerformed(ActionEvent e){ group.clearSelection(); } } public JRadioButton addRadioButton(JPanel buttonPanel,ButtonGroup g,String buttonName,boolean v){ JRadioButton button = new JRadioButton(buttonName,v); g.add(button); buttonPanel.add(button); return button; } public static void main(String[] args){ JFrame frame = new RadioButtonTest(); frame.setVisible(true); }} Java串口编程数据接收的问题??? 一个面试题 求助:对getFilePointer() 的结果感到疑惑 循环语句从1到26建立26个checkbox? 一个用java对文本操作的问题 java错误日志 真心的请教大家!!Java对我来说是一个全新的世界,我现在还不知道是什么?我很想征服它 如何在启动一个java application应用前先调用显示一个flash得.swf文件 别人给了一个xxx.class的文件和一个接口说明,在linux下如何编程调用? 为什么在安装JDK1.4.2时会出错? 如何实现把一个目录中的JPG格式的文件读入JList中? java 小问题 二维数组
JButton jbt = new JButton("重置");
JRadioButton[] jrbts = new JRadioButton[4];
ButtonGroup group;
public RadioButtonTest(){
setTitle("RadioButtonTest");
setSize(400,200);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
JPanel buttonPanel = new JPanel();
group = new ButtonGroup();
for(int i = 0;i < jrbts.length ;i ++){
jrbts[i] = new JRadioButton();
addRadioButton(buttonPanel,group,"jrbts["+i+"]",false);
}
getContentPane().add(buttonPanel,"South");
jbt.addActionListener(new MyListener());
getContentPane().add(jbt,"Center");
} class MyListener implements ActionListener{
public void actionPerformed(ActionEvent e){
group.clearSelection();
}
} public JRadioButton addRadioButton(JPanel buttonPanel,ButtonGroup g,String buttonName,boolean v){
JRadioButton button = new JRadioButton(buttonName,v);
g.add(button);
buttonPanel.add(button);
return button;
} public static void main(String[] args){
JFrame frame = new RadioButtonTest();
frame.setVisible(true);
}
}