试卷内容21047_带答案

更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
下面程序有4处错误,请改正。 public class JRadioButton_Example extends JFrame { // 继承窗体类 JFrame public JRadioButton_Example() { super(); // 继承父类的构造方法 setTitle("单选按钮组件示例"); // 设置窗体的标题 setBounds(100, 100, 500, 375); // 设置窗体的显示位置及大小 getContentPane().setLayout(null); // 设置为不采用任何布局管理器 /**********ERROR**********/ setDefaultCloseOperation(EXIT_ON_CLOSE); // 设置窗体关闭按钮的动作为退出 /**********ERROR**********/ JLabel label = new Label(); // 创建标签对象 label.setText("性别:"); // 设置标签文本 label.setBounds(10, 10, 46, 15); // 设置标签的显示位置及大小 /**********ERROR**********/ getContentPane().Add(label); // 将标签添加到窗体中 ButtonGroup buttonGroup = new ButtonGroup(); // 创建按钮组对象 JRadioButton manRadioButton = new JRadioButton(); // 创建单选按钮对象 buttonGroup.add(manRadioButton); // 将单选按钮添加到按钮组中 /**********ERROR**********/ manRadioButton.setSelected(); // 设置单选按钮默认为被选中 manRadioButton.setText("男"); // 设置单选按钮的文本 manRadioButton.setBounds(62, 6, 46, 23); // 设置单选按钮的显示位置及大小 getContentPane().add(manRadioButton); // 将单选按钮添加到窗体中 JRadioButton womanRadioButton = new JRadioButton(); buttonGroup.add(womanRadioButton); womanRadioButton.setText("女"); womanRadioButton.setBounds(114, 6, 46, 23); getContentPane().add(womanRadioButton); } public static void main(String args[]) { JRadioButton_Example frame = new JRadioButton_Example(); frame.setVisible(true); // 设置窗体可见,默认为不可见 } }