中易网

java个人信息调查表都用到了哪些知识点?

答案:2  悬赏:0  
解决时间 2021-04-27 22:44
  • 提问者网友:伪情浪人
  • 2021-04-27 03:49

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();
 }
}

最佳答案
  • 二级知识专家网友:我的任性你不懂
  • 2021-04-27 04:55
用到了GUI(图形界面设计)、使用了 java.awt 的软件包、java.awt.event 的软件包 (事件和监听器类)、javax.swing 的软件包(Swing组件和实用工具)、java.awt.event 中的接口 ActionListener、
javax.swing 中的类:[JFrame(窗体)、JPanel(面板)、JRadioButton(单选按钮)、JLabel(标签)、JCheckBox(复选框)、JButton(按钮)、
JTextField(文件输入框)、ButtonGroup(按钮组)]、窗体组件常用方法:(setBounds、setVisible、setResizable、setDefaultCloseOperation)、设置布局管理器、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("你的年龄:");//创建标签
全部回答
  • 1楼网友:错过的是遗憾
  • 2021-04-27 06:13
java的swing、数组、if控制语句,没了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息