更新時(shí)間:2022-12-30 11:50:34 來源:動(dòng)力節(jié)點(diǎn) 瀏覽1651次
實(shí)現(xiàn)Java單選框的代碼是什么?動(dòng)力節(jié)點(diǎn)小編來告訴大家。
public class JButtonDemo02 extends JFrame {
public JButtonDemo02() {
Container container = this.getContentPane();
//將一個(gè)圖片變?yōu)閳D標(biāo)
URL resource = JButtonDemo01.class.getResource("tx.jpg");
Icon icon = new ImageIcon(resource);
//單選框
JRadioButton RadioButton1 = new JRadioButton("JRadioButton");
JRadioButton RadioButton2 = new JRadioButton("JRadioButton");
JRadioButton RadioButton3 = new JRadioButton("JRadioButton");
//由于單選框只能選擇一個(gè),分組
ButtonGroup group = new ButtonGroup();
group.add(RadioButton1);
group.add(RadioButton2);
group.add(RadioButton3);
container.add(RadioButton1,BorderLayout.CENTER);
container.add(RadioButton2,BorderLayout.NORTH);
container.add(RadioButton3,BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(500,300);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// new JButtonDemo01();
new JButtonDemo02();
}
}
相關(guān)閱讀
初級 202925
初級 203221
初級 202629
初級 203743