201771010124 王海珍 《面向对象设计 java》第十八周总结
Posted www-whz-1997
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了201771010124 王海珍 《面向对象设计 java》第十八周总结相关的知识,希望对你有一定的参考价值。
1、实验目的与要求
(1) 综合掌握java基本程序结构;
(2) 综合掌握java面向对象程序设计特点;
(3) 综合掌握java GUI 程序设计结构;
(4) 综合掌握java多线程编程模型;
(5) 综合编程练习。
2、实验内容和步骤
任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx。
任务2:综合编程练习
练习1:设计一个用户信息采集程序,要求如下:
1 package project1;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6 import javax.swing.border.*;
7
8 public class test extends JFrame {
9 public test() {
10 JPanel panel1 = new JPanel();
11 panel1.setPreferredSize(new Dimension(700, 45));
12 panel1.setLayout(new GridLayout(1, 4));
13 JLabel label1 = new JLabel("Name:");
14 JTextField j1 = new JTextField("");
15 JLabel label2 = new JLabel("Qualification:");
16 JComboBox<Object> j2 = new JComboBox<>();
17 j2.addItem("Graduate");
18 j2.addItem("Not Graduate");
19 panel1.add(label1);
20 panel1.add(j1);
21 panel1.add(label2);
22 panel1.add(j2);
23
24 JPanel panel2 = new JPanel();
25 panel2.setPreferredSize(new Dimension(700, 50));
26 panel2.setLayout(new GridLayout(1, 4));
27 JLabel label3 = new JLabel("Address:");
28 JTextArea j3 = new JTextArea();
29 JLabel label4 = new JLabel("Hobby:");
30 JPanel p = new JPanel();
31 p.setLayout(new GridLayout(3, 1));
32 p.setBorder(BorderFactory.createLineBorder(null));
33 JCheckBox c1 = new JCheckBox("Reading");
34 JCheckBox c2 = new JCheckBox("Singing");
35 JCheckBox c3 = new JCheckBox("Dancing");
36 p.add(c1);
37 p.add(c2);
38 p.add(c3);
39 panel2.add(label3);
40 panel2.add(j3);
41 panel2.add(label4);
42 panel2.add(p);
43
44 JPanel panel3 = new JPanel();
45 panel3.setPreferredSize(new Dimension(700, 150));
46 FlowLayout flowLayout1 = new FlowLayout(FlowLayout.CENTER, 50, 10);
47 panel3.setLayout(flowLayout1);
48 JLabel label5 = new JLabel("Sex:");
49 JPanel p1 = new JPanel();
50 p1.setLayout(new GridLayout(2, 1));
51 p1.setBorder(BorderFactory.createLineBorder(null));
52 ButtonGroup bu = new ButtonGroup();
53 JRadioButton jr1 = new JRadioButton("Male");
54 JRadioButton jr2 = new JRadioButton("Female");
55 bu.add(jr1);
56 bu.add(jr2);
57 p1.add(jr1);
58 p1.add(jr2);
59 panel3.add(label5);
60 panel3.add(p1);
61 add(panel1);
62 add(panel2);
63 add(panel3);
64
65 JPanel panel4 = new JPanel();
66 panel4.setPreferredSize(new Dimension(700, 150));
67 JButton b1 = new JButton("Validate");
68 panel4.add(b1);
69 JButton b2 = new JButton("Reset");
70 panel4.add(b2);
71 add(panel4);
72
73 FlowLayout flowLayout = new FlowLayout();
74 this.setLayout(flowLayout);
75 this.setTitle("Students Detail");
76 this.setBounds(200, 200, 800, 400);
77 this.setVisible(true);
78 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
79
80 b1.addActionListener(new ActionListener() {
81
82 @Override
83 public void actionPerformed(ActionEvent e) {
84 String xueli = j2.getSelectedItem().toString();
85 System.out.println("Name:" + j1.getText());
86 System.out.println("Qualification:" + xueli);
87 String hobbystring = "Hobby:";
88 if (c1.isSelected()) {
89 hobbystring += "Reading";
90 }
91 if (c2.isSelected()) {
92 hobbystring += "Singing";
93 }
94 if (c3.isSelected()) {
95 hobbystring += "Dancing";
96 }
97 System.out.println("Address:" + j3.getText());
98 if (jr1.isSelected()) {
99 System.out.println("Sex:Male");
100