/* Swingサンプル */ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import java.awt.Container; import java.awt.BorderLayout; class SSample11_1 extends JFrame{ public static void main(String args[]){ SSample11_1 frame = new SSample11_1("タイトル"); frame.setVisible(true); } SSample11_1(String title){ setTitle(title); setBounds(100, 100, 300, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); ImageIcon icon1 = new ImageIcon("./calculator.png"); ImageIcon icon2 = new ImageIcon("./camera.png"); ImageIcon icon3 = new ImageIcon("./clock.png"); ImageIcon icon4 = new ImageIcon("./computer.png"); ImageIcon sicon1 = new ImageIcon("./select_calculator.png"); ImageIcon sicon2 = new ImageIcon("./select_camera.png"); ImageIcon sicon3 = new ImageIcon("./select_clock.png"); ImageIcon sicon4 = new ImageIcon("./select_computer.png"); JRadioButton radio1 = new JRadioButton(icon1); radio1.setSelectedIcon(sicon1); JRadioButton radio2 = new JRadioButton(icon2, true); radio2.setSelectedIcon(sicon2); JRadioButton radio3 = new JRadioButton(icon3); radio3.setSelectedIcon(sicon3); JRadioButton radio4 = new JRadioButton(icon4); radio4.setSelectedIcon(sicon4); ButtonGroup group = new ButtonGroup(); group.add(radio1); group.add(radio2); group.add(radio3); group.add(radio4); p.add(radio1); p.add(radio2); p.add(radio3); p.add(radio4); Container contentPane = getContentPane(); contentPane.add(p, BorderLayout.CENTER); } }