| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1158 人关注过本帖
标题:[求助]一个比较菜的问题
取消只看楼主 加入收藏
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
 问题点数:0 回复次数:3 
[求助]一个比较菜的问题
今天学Swing,问一个比较菜的问题.
怎么添加单选按钮组,怎么使用ButtonGroup这个类.
谢谢大家。。
搜索更多相关主题的帖子: ButtonGroup Swing 按钮 
2006-06-22 16:50
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
得分:0 

晕,看不懂。我们今天只学了怎么用JBuilder自动生成代码
有个地方不会写。。。。
package studentapplication;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.JTextPane;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.border.Border;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class StudentApplicationFrameClass extends JFrame {
JPanel contentPane;
JLabel lblName = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JRadioButton jRadioButton1 = new JRadioButton();
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
ButtonGroup button = new ButtonGroup();
这里接下来这么写,就是让性别只能选一个
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
Border border1 = BorderFactory.createEtchedBorder(Color.lightGray,
new Color(148, 145, 140));
public StudentApplicationFrameClass() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Students Detail");
lblName.setText("姓名");
lblName.setBounds(new Rectangle(34, 55, 42, 15));
jTextField1.setBounds(new Rectangle(69, 54, 72, 21));
jLabel2.setText("资历");
jLabel2.setBounds(new Rectangle(214, 55, 42, 15));
jComboBox1.setBounds(new Rectangle(283, 55, 66, 23));
jComboBox1.addItem("本科生");
jComboBox1.addItem("研究生");
jComboBox1.addItem("工程师");
jComboBox1.addItem("博士");
jComboBox1.addItem("其他");
jLabel4.setText("兴趣");
jLabel4.setBounds(new Rectangle(214, 113, 42, 15));
jLabel5.setText("性别");
jLabel5.setBounds(new Rectangle(34, 203, 42, 15));
jLabel3.setText("地址");
jLabel3.setBounds(new Rectangle(34, 118, 42, 15));
jTextArea1.setBounds(new Rectangle(69, 115, 83, 60));
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(271, 100, 95, 77));
jPanel1.setLayout(null);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setBounds(new Rectangle(63, 191, 97, 79));
jPanel2.setLayout(null);
jRadioButton1.setSelected(true);
jRadioButton1.setText("男");
jRadioButton1.setBounds(new Rectangle(17, 12, 103, 23));
jCheckBox1.setText("阅读");
jCheckBox1.setBounds(new Rectangle(19, 6, 85, 23));
jCheckBox2.setText("唱歌");
jCheckBox2.setBounds(new Rectangle(19, 27, 85, 23));
jCheckBox3.setText("跳舞");
jCheckBox3.setBounds(new Rectangle(19, 50, 85, 23));
jRadioButton2.setText("女");
jRadioButton2.setBounds(new Rectangle(17, 45, 103, 23));
jButton1.setBounds(new Rectangle(207, 244, 83, 25));
jButton1.setText("验证");
jButton2.setBounds(new Rectangle(308, 244, 83, 25));
jButton2.setText("重置");
contentPane.setBorder(border1);
contentPane.add(lblName);
contentPane.add(jLabel2);
contentPane.add(jComboBox1);
contentPane.add(jLabel4);
contentPane.add(jLabel5);
contentPane.add(jLabel3);
jPanel1.add(jCheckBox1);
jPanel1.add(jCheckBox2);
jPanel1.add(jCheckBox3);
jPanel2.add(jRadioButton2);
jPanel2.add(jRadioButton1);
contentPane.add(jPanel1);
contentPane.add(jTextArea1);
contentPane.add(jTextField1);
contentPane.add(jButton1);
contentPane.add(jButton2);
contentPane.add(jPanel2);
}
}


曾经以为百般艰难,蓦然回首,才发现已飞渡千山。。!
2006-06-22 17:06
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
得分:0 

材料学本科,现在在上培训机构。
package studentapplication;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.JTextPane;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.border.Border;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class StudentApplicationFrameClass extends JFrame {
JPanel contentPane;
JLabel lblName = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JRadioButton jRadioButton1 = new JRadioButton();
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
ButtonGroup button = new ButtonGroup();
这里下面该怎么写啊?




JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
Border border1 = BorderFactory.createEtchedBorder(Color.lightGray,
new Color(148, 145, 140));
public StudentApplicationFrameClass() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Students Detail");
lblName.setText("姓名");
lblName.setBounds(new Rectangle(34, 55, 42, 15));
jTextField1.setBounds(new Rectangle(69, 54, 72, 21));
jLabel2.setText("资历");
jLabel2.setBounds(new Rectangle(214, 55, 42, 15));
jComboBox1.setBounds(new Rectangle(283, 55, 66, 23));
jComboBox1.addItem("本科生");
jComboBox1.addItem("研究生");
jComboBox1.addItem("工程师");
jComboBox1.addItem("博士");
jComboBox1.addItem("其他");
jLabel4.setText("兴趣");
jLabel4.setBounds(new Rectangle(214, 113, 42, 15));
jLabel5.setText("性别");
jLabel5.setBounds(new Rectangle(34, 203, 42, 15));
jLabel3.setText("地址");
jLabel3.setBounds(new Rectangle(34, 118, 42, 15));
jTextArea1.setBounds(new Rectangle(69, 115, 83, 60));
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(271, 100, 95, 77));
jPanel1.setLayout(null);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setBounds(new Rectangle(63, 191, 97, 79));
jPanel2.setLayout(null);
jRadioButton1.setSelected(true);
jRadioButton1.setText("男");
jRadioButton1.setBounds(new Rectangle(17, 12, 103, 23));
jCheckBox1.setText("阅读");
jCheckBox1.setBounds(new Rectangle(19, 6, 85, 23));
jCheckBox2.setText("唱歌");
jCheckBox2.setBounds(new Rectangle(19, 27, 85, 23));
jCheckBox3.setText("跳舞");
jCheckBox3.setBounds(new Rectangle(19, 50, 85, 23));
jRadioButton2.setText("女");
jRadioButton2.setBounds(new Rectangle(17, 45, 103, 23));
jButton1.setBounds(new Rectangle(207, 244, 83, 25));
jButton1.setText("验证");
jButton2.setBounds(new Rectangle(308, 244, 83, 25));
jButton2.setText("重置");
contentPane.setBorder(border1);
contentPane.add(lblName);
contentPane.add(jLabel2);
contentPane.add(jComboBox1);
contentPane.add(jLabel4);
contentPane.add(jLabel5);
contentPane.add(jLabel3);
jPanel1.add(jCheckBox1);
jPanel1.add(jCheckBox2);
jPanel1.add(jCheckBox3);
jPanel2.add(jRadioButton2);
jPanel2.add(jRadioButton1);
contentPane.add(jPanel1);
contentPane.add(jTextArea1);
contentPane.add(jTextField1);
contentPane.add(jButton1);
contentPane.add(jButton2);
contentPane.add(jPanel2);
}
}


曾经以为百般艰难,蓦然回首,才发现已飞渡千山。。!
2006-06-22 17:20
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
得分:0 
哦,我会写了,谢谢水影啊,你的代码对我就点启发~!哎,真苯~!

曾经以为百般艰难,蓦然回首,才发现已飞渡千山。。!
2006-06-22 17:33
快速回复:[求助]一个比较菜的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038476 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved