java swing如何获取单选框的值
2个回答
展开全部
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class MyTest extends JFrame{
private JRadioButton jrb;
public MyTest(){
jrb = new JRadioButton("click here");
this.setLayout(new FlowLayout());
this.add(jrb);
this.setSize(500,500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public boolean getJRadioButtonValue(){
return jrb.isSelected();
}
public static void main(String[] args){
MyTest my = new MyTest();
my.jrb.setSelected(true);
System.out.println(my.getJRadioButtonValue());
my.jrb.setSelected(false);
System.out.println(my.getJRadioButtonValue());
}
}
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class MyTest extends JFrame{
private JRadioButton jrb;
public MyTest(){
jrb = new JRadioButton("click here");
this.setLayout(new FlowLayout());
this.add(jrb);
this.setSize(500,500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public boolean getJRadioButtonValue(){
return jrb.isSelected();
}
public static void main(String[] args){
MyTest my = new MyTest();
my.jrb.setSelected(true);
System.out.println(my.getJRadioButtonValue());
my.jrb.setSelected(false);
System.out.println(my.getJRadioButtonValue());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |