穷吉201771010119总复习
Posted qiongji
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了穷吉201771010119总复习相关的知识,希望对你有一定的参考价值。
实验十八 总复习
实验时间 2018-12-30
1、实验目的与要求
(1) 综合掌握java基本程序结构;
(2) 综合掌握java面向对象程序设计特点;
(3) 综合掌握java GUI 程序设计结构;
(4) 综合掌握java多线程编程模型;
(5) 综合编程练习。
2、实验内容和步骤
任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx。
任务2:综合编程练习
练习1:设计一个用户信息采集程序,要求如下:
(1) 用户信息输入界面如下图所示:
(1)用户点击提交按钮时,用户输入信息显示控制台界面;
(2)用户点击重置按钮后,清空用户已输入信息;
(3)点击窗口关闭,程序退出。
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class DemoJFrame extends JFrame {
private JPanel jPanel1;
private JPanel jPanel2;
private JPanel jPanel3;
private JPanel jPanel4;
private JTextField fieldname;
private JComboBox comboBox;
private JTextField fieldadress;
private ButtonGroup bg;
private JRadioButton male;
private JRadioButton female;
private JCheckBox read;
private JCheckBox movie;
private JCheckBox learn;
public DemoJFrame() {
// 设置窗口大小
this.setSize(800, 400);
// 设置可见性
this.setVisible(true);
// 设置标题
this.setTitle("编程练习一");
// 设置关闭操作
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
// 设置窗口居中
WinCenter.center(this);
// 创建四个面板对象
jPanel1 = new JPanel();
setJPanel1(jPanel1);
jPanel2 = new JPanel();
setJPanel2(jPanel2);
jPanel3 = new JPanel();
setJPanel3(jPanel3);
jPanel4 = new JPanel();
setJPanel4(jPanel4);
// 设置容器的为流布局
FlowLayout flowLayout = new FlowLayout();//构造一个新的 FlowLayout,它是居中对齐的
this.setLayout(flowLayout);
// 将四个面板添加到容器中
this.add(jPanel1);
this.add(jPanel2);
this.add(jPanel3);
this.add(jPanel4);
}
/*
* 设置面一
*/
private void setJPanel1(JPanel jPanel) {
// TODO 自动生成的方法存根
jPanel.setPreferredSize(new Dimension(700, 45));
// 给面板的布局设置为网格布局 一行4列
jPanel.setLayout(new GridLayout(1, 4));
JLabel name = new JLabel("姓名:");
name.setSize(100, 50);
fieldname = new JTextField("");
fieldname.setSize(80, 20);
JLabel study = new JLabel("学历:");
comboBox = new JComboBox();
comboBox.addItem("初中");
comboBox.addItem("高中");
comboBox.addItem("本科");
jPanel.add(name);
jPanel.add(fieldname);
jPanel.add(study);
jPanel.add(comboBox);
}
/*
* 设置面板二
*/
private void setJPanel2(JPanel jPanel) {
// TODO 自动生成的方法存根
jPanel.setPreferredSize(new Dimension(700, 50));
// 给面板的布局设置为网格布局 一行4列
jPanel.setLayout(new GridLayout(1, 4));
JLabel name = new JLabel("地址:");
fieldadress = new JTextField();
fieldadress.setPreferredSize(new Dimension(150, 50));
JLabel study = new JLabel("爱好:");
JPanel selectBox = new JPanel();
selectBox.setBorder(BorderFactory.createTitledBorder(""));//创建一个新标题边框
selectBox.setLayout(new GridLayout(3, 1));//创建具有指定行数和列数的网格布局。给布局中的所有组件分配相等的大小。
read = new JCheckBox("读书");
movie = new JCheckBox("看电影");
learn = new JCheckBox("学习");
selectBox.add(read);
selectBox.add(movie);
selectBox.add(learn);
jPanel.add(name);
jPanel.add(fieldadress);
jPanel.add(study);
jPanel.add(selectBox);
}
/*
* 设置面板三
*/
private void setJPanel3(JPanel jPanel) {
// TODO 自动生成的方法存根
jPanel.setPreferredSize(new Dimension(700, 150));
FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT);
jPanel.setLayout(flowLayout);
JLabel sex = new JLabel("性别:");
JPanel selectBox = new JPanel();
selectBox.setBorder(BorderFactory.createTitledBorder(""));
selectBox.setLayout(new GridLayout(2, 1));
bg = new ButtonGroup();
male = new JRadioButton("男");
female = new JRadioButton("女");
bg.add(male);
bg.add(female);
selectBox.add(male);
selectBox.add(female);
jPanel.add(sex);
jPanel.add(selectBox);
}
/*
* 设置面板四
*/
private void setJPanel4(JPanel jPanel) {
// TODO 自动生成的方法存根
jPanel.setPreferredSize(new Dimension(700, 150));
FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 50, 10);
jPanel.setLayout(flowLayout);
jPanel.setLayout(flowLayout);
JButton sublite = new JButton("提交");
JButton reset = new JButton("重置");
sublite.addActionListener((e) -> valiData());
reset.addActionListener((e) -> Reset());//给提交和重置按钮创建监听器
jPanel.add(sublite);
jPanel.add(reset);
}
/*
* 提交数据
*/
private void valiData() {
//