java个人信息调查表都用到了哪些知识点?如package game;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Survry extends JFrame implements ActionListener {
private JPanel jp = new JPanel();
private JRadioButton man = new JRadioButton("男",true);
private JRadioButton woman = new JRadioButton("女");
ButtonGroup sexBG = new ButtonGroup();
JLabel sexSTR = new JLabel("你的性别:");
JLabel likeSTR = new JLabel("你的爱好:");
JLabel ageSTR = new JLabel("你的年龄:");
private JCheckBox[] jcbArray = {new JCheckBox("灌水"), new JCheckBox("游戏"),
new JCheckBox("发呆"), new JCheckBox("旅游"),
new JCheckBox("其他")};
private JRadioButton[] jrbArray = {new JRadioButton("小学毕业"),
new JRadioButton("亭亭玉立", true),
new JRadioButton("而立之年"),
new JRadioButton("大展宏图"),
new JRadioButton("涛声依旧")};
private JButton[] jbArray = {new JButton("提交"), new JButton("清空")};
private JLabel[] jlArray = {new JLabel("年龄段:"), new JLabel("兴趣爱好:"),
new JLabel("调查的结果为:")};
private JTextField otherTF = new JTextField();
private JTextField jtf = new JTextField();
private ButtonGroup bg = new ButtonGroup();
boolean isViewOtherTF = false;
public Survry() {
jp.setLayout(null);
sexBG.add(man);
sexBG.add(woman);
man.setBounds(100, 20, 50, 30);
woman.setBounds(150, 20, 50, 30);
jp.add(man);
jp.add(woman);
sexSTR.setBounds(30, 20, 75, 30);
jp.add(sexSTR);
likeSTR.setBounds(30, 50, 75, 30);
jp.add(likeSTR);
ageSTR.setBounds(30, 80, 75, 30);
jp.add(ageSTR);
for (int i = 0; i < jcbArray.length; i++) {
jcbArray[i].setBounds(60 * i + 100, 50, 60, 30);
jp.add(jcbArray[i]);
}
otherTF.setBounds(410, 50, 100, 22);
jp.add(otherTF);
otherTF.setVisible(false);
jcbArray[jcbArray.length - 1].addActionListener(this);
for (int i = 0; i < jrbArray.length; i++) {
jrbArray[i].setBounds(90 * i + 100, 80, 90, 30);
jp.add(jrbArray[i]);
bg.add(jrbArray[i]);
}
jbArray[0].setBounds(30, 110, 80, 30);
jp.add(jbArray[0]);
jbArray[1].setBounds(120, 110, 80, 30);
jp.add(jbArray[1]);
jbArray[0].addActionListener(this);
jbArray[1].addActionListener(this);
jtf.setBounds(120, 150, 500, 26);
jp.add(jtf);
jtf.setEditable(false);
this.add(jp);
this.setTitle("个人信息调查表");
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() == jcbArray[jcbArray.length - 1]){
if(isViewOtherTF){
otherTF.setVisible(false);
isViewOtherTF = false;
}else{
otherTF.setVisible(true);
isViewOtherTF = true;
}
}
if (e.getSource() == jbArray[1]) {
if(isViewOtherTF){
otherTF.setVisible(false);
isViewOtherTF = false;
}
for (int i = 0; i < jcbArray.length; i++){
jcbArray[i].setSelected(false);
}
jtf.setText("");
otherTF.setText("");
sexBG.setSelected(man.getModel(),true);
bg.setSelected(jrbArray[1].getModel(),true);
}
if (e.getSource() == jbArray[0]) {
StringBuffer temp1 = new StringBuffer("你是一个");
StringBuffer temp2 = new StringBuffer();
for (int i = 0; i < 5; i++) {
if (jrbArray[i].isSelected()) {
temp1.append(jrbArray[i].getText());
}
if (jcbArray[i].isSelected()) {
if (i == 4) {
temp2.append(otherTF.getText());
} else {
temp2.append(jcbArray[i].getText() + ",");
}
}
}
if (temp2.length() == 0) {
jtf.setText("难道你没有爱好?");
} else {
temp1.append("的人,你比较喜欢");
temp1.append(temp2.substring(0, temp2.length() - 1));
jtf.setText(temp1.append("。").toString());
}
}
}
public static void main(String[] args) {
new Survry();
}
}