java中点击按钮使选中的jRadioButton变成未选中,怎么实现?

来源:百度知道 编辑:UC知道 时间:2024/05/06 18:22:58

有一笨方法:使焦点选中另外的地方

代码你自己研究下

package test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class Test extends JPanel {
private JRadioButton radGolfNo ;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new Test());

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}

public Test(){
radGolfNo = new JRadioButton("2No2?", true);
JButton b = new JButton("xuan");
b.addActionListener(new ButtonListener());
setLayout(null);
add(radGolfNo);
add(b);
b.setBounds(30, 100, 30, 30);
radGolfNo.setBounds(150, 80, 50, 20);