checkAndRadio.zip
- 丁军峰了解作者
- Java开发工具
- 1KB文件大小
- zip文件格式
- 0收藏次数
- 1 积分下载积分
- 1下载次数
- 2015-02-10 18:39上传日期
JAVA基础课,了解单选、多选按钮必备代码

checkAndRadio.zip
- checkAndRadio.java2.5KB
内容介绍
import java.awt.event.*;
import javax.swing.*;
public class checkAndRadio extends JFrame implements ActionListener
{
private JPanel jp=new JPanel();
private JCheckBox[] jcbArray=
{
new JCheckBox("internet"),
new JCheckBox("sport"),
new JCheckBox("car"),
new JCheckBox("victry"),
new JCheckBox("fashion")
};
private JRadioButton[] jrbArray=
{
new JRadioButton("5~14"),
new JRadioButton ("16~25",true),
new JRadioButton ("26~35"),
new JRadioButton ("36~45"),
new JRadioButton ("46~55")
};
private JButton[] jbArray={new JButton("up"),new JButton("clear")};
private JLabel[] jlArray=
{new JLabel("age"),new JLabel("hobes"),new JLabel("end")};
private JTextField jtf=new JTextField();
private ButtonGroup bg=new ButtonGroup();
public checkAndRadio()
{
jp.setLayout(null);
for(int i=0;i<5;i++)
{
jrbArray[i].setBounds(40+i*100,40,80,30);
jcbArray[i].setBounds(40+i*120,100,120,30);
jp.add(jrbArray[i]);
jp.add(jcbArray[i]);
jrbArray[i].addActionListener(this);
jcbArray[i].addActionListener(this);
bg.add(jrbArray[i]);
if(i>1)continue;
jlArray[i].setBounds(20,20+i*50,80,30);
jbArray[i].setBounds(400+i*120,200,80,26);
jp.add(jlArray[i]);
jp.add(jbArray[i]);
jbArray[i].addActionListener(this);
}
jlArray[2].setBounds(20,150,120,30);
jp.add(jlArray[2]);
jtf.setBounds(120,150,500,26);
jp.add(jtf);
jtf.setEditable(false);
this.add(jp);
this.setTitle("information");//////////////
this.setBounds(100,100,700,280);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbArray[1])
{
bg.clearSelection();
for(int i=0;i<jcbArray.length;i++)
jcbArray[i].setSelected(false);
jtf.setText("");
}
else
{
StringBuffer temp1=new StringBuffer("you are a");///////////
StringBuffer temp2=new StringBuffer();
for(int i=0;i<5;i++)
{
if(jrbArray[i].isSelected())
{
temp1.append(jrbArray[i].getText());
}
if(jcbArray[i].isSelected())
{
temp2.append(jcbArray[i].getText()+",");
}
}
if(temp2.length()==0)
{
jtf.setText("intresting can not be null");
}
else
{
temp1.append("s,you'd like");////
temp1.append(temp2.substring(0,temp2.length()-1));
jtf.setText(temp1.append(".").toString());
}
}
}
public static void main(String[] args)
{
new checkAndRadio();
}
}
评论

相关推荐
- 蓝桥杯历年真题(国赛+省赛)蓝桥杯2013年到2017年国赛真题,A组,B组,C组。包含解题思路和答案。 省赛真题历年5年的 必刷题,蓝桥杯大多都是模型题。看多了,做多了,相对还是容易混个证书。
- 蓝桥杯历年真题答案里面包含了c和java的一下算法题目和答案。希望能帮助到大家.
- 蓝桥杯C语言历年真题与答案蓝桥杯C语言历年真题与答案,不能说完整,但是有2011到2014的。
- 蓝桥杯历年真题(决赛B组C)经过多处搜索,找到终于合成这个压缩包,自己亲身做了一些,简单题都附上了代码、答案,绝对物有所值。
- 蓝桥杯历年真题.rar第七届至第十一届蓝桥杯各组别省赛真题
- 蓝桥杯历年真题 预赛题目(省赛)java A-B-C组
- 蓝桥杯历年真题,,,蓝桥杯真题和答案,一起拿到奖加油
- 蓝桥杯历年真题.zip蓝桥杯历年真题.zip
- 蓝桥杯历年真题里面包含了c和java的一下算法题目和答案。希望能帮助到大家.
- 蓝桥杯Java历年真题及答案包含四个文件,很全面的蓝桥杯资源: jdk环境配置.doc 蓝桥杯历年真题及答案.docx 蓝桥杯练习系统题目汇总.doc 蓝桥杯java历年真题及答案整理(共129道题目及答案).doc