このページは、学部2年生向け授業である、「マルチメディアプログラミング実習」 のために用意しました。
(Wikiの仕様で大文字小文字が混在した英単語に疑問符?が追加されるところがありますが、無視してください。)
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JRadioButtonSample extends JFrame {
public void initialize() {
this.setTitle("Radio Buttons");
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JRadioButton radio1 = new JRadioButton("for here");
JRadioButton radio2 = new JRadioButton("to go");
ButtonGroup group = new ButtonGroup();
group.add(radio1);
group.add(radio2);
panel1.setLayout(new GridLayout(2,1));
panel2.setLayout(new GridLayout(3,1));
panel1.add(radio1);
panel1.add(radio2);
panel2.add(new JCheckBox("with Drink"));
panel2.add(new JCheckBox("with Salad"));
panel2.add(new JCheckBox("with Cake"));
Container container = this.getContentPane();
container.add(panel1,BorderLayout.WEST);
container.add(panel2,BorderLayout.EAST);
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String args[]) {
JRadioButtonSample jrbs = new JRadioButtonSample();
jrbs.initialize();
}
}