求一段JAVA代码(实例代码)

来源:百度知道 编辑:UC知道 时间:2024/05/09 14:36:45
就是说求Checkbox ,RADIONBUTTON,的简单事例代码,要求确定返回一些关于这些对象的内容

import java.awt.event.*;
import javax.swing.*;
public class FrameTest {
public static void main(String[] args) {
new F().setVisible(true);
}
}
class F extends JFrame implements ActionListener{
JCheckBox a,b,c;
JRadioButton d,e,f;
ButtonGroup g;
F(){
this.setSize(400,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(new java.awt.GridLayout(2,3));
a = new JCheckBox("JCheckBox A",true);//默认为选中
b = new JCheckBox("JCheckBox B");
c = new JCheckBox("JCheckBox C");
a.addActionListener(this);
b.addActionListener(this);
c.addActionListener(this);
add(a);
add(b);
add(c);

d = new JRadioButton("JRadioButton 1");
e = new JRadioButton("JRadioButton 2");
f = new JRadioButton("JRadioButton 3");
d.addActionListener(this);