更新時間:2022-12-30 11:50:34 來源:動力節點 瀏覽1801次
實現Java單選框的代碼是什么?動力節點小編來告訴大家。
public class JButtonDemo02 extends JFrame {
public JButtonDemo02() {
Container container = this.getContentPane();
//將一個圖片變為圖標
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");
//由于單選框只能選擇一個,分組
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();
}
}
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習