实验十八  总复习

1、实验目的与要求              

(1) 综合掌握java基本程序结构;

(2) 综合掌握java面向对象程序设计特点;

(3) 综合掌握java GUI 程序设计结构;

(4) 综合掌握java多线程编程模型;

(5) 综合编程练习。

2、实验内容和步骤

任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx。

任务2:综合编程练习

练习1:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;public class Yonghu
{public static void main(String[] args){EventQueue.invokeLater(() -> {JFrame frame = new FrameTest();frame.setTitle("信息采集");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});}
}class FrameTest extends JFrame
{private JPanel panel1;private JTextArea text1,text2;private JRadioButton JRadioButton1,JRadioButton2;private ButtonGroup ButtonGroup1;private JLabel JLabel1;private JCheckBox checkboxb1,checkboxb2,checkboxb3;private JComboBox<String> JComboBox1;private JButton Button1,Button2;public FrameTest(){setSize(700,500);panel1=new JPanel();panel1.setLayout(null);ButtonGroup1=new ButtonGroup();JRadioButton1=new JRadioButton("Male",false);   JRadioButton1.setBounds(150,330, 80, 50);JRadioButton2=new JRadioButton("Female",false); JRadioButton2.setBounds(150,300, 80,50);ButtonGroup1.add(JRadioButton1);ButtonGroup1.add(JRadioButton2);addJLabel("sex:",100,300);addJLabel("name:",100,50);addJLabel("address:",100,150);addJLabel("Qualification:",400,50);addJLabel("Hobby:",400,150);text1=new JTextArea(1,1);text1.setBounds(150,70, 120, 30);text1.setLineWrap(true);text2=new JTextArea(5,3);text2.setBounds(150,160, 130, 100);text2.setLineWrap(true);checkboxb1=new JCheckBox("Reading");checkboxb1.setBounds(450,160,100,30);checkboxb2=new JCheckBox("Dancing");checkboxb2.setBounds(450,180,100,30);checkboxb3=new JCheckBox("Singing");checkboxb3.setBounds(450,200,100,30);JComboBox1=new JComboBox<>();JComboBox1.addItem("Graduate");JComboBox1.addItem("Sinior");JComboBox1.addItem("Junior");JComboBox1.setBounds(500,65, 100, 20);Button1 = new JButton("提交");Button1.setBounds(200, 400, 100, 35);Button2 = new JButton("重置");Button2.setBounds(400, 400, 100, 35);Button1.addActionListener(new Action1());Button2.addActionListener(new Action2());panel1.add(checkboxb1);panel1.add(checkboxb2);panel1.add(checkboxb3);panel1.add(Button1);panel1.add(Button2);panel1.add(JComboBox1);panel1.add(text1);panel1.add(text2);panel1.add(JRadioButton1);panel1.add(JRadioButton2);add(panel1);}public void addJLabel(String n,int a,int b){JLabel1 = new JLabel(n);JLabel1.setBounds(a,b,100,50);panel1.add(JLabel1);}private class Action1 implements ActionListener{public void actionPerformed(ActionEvent event){        System.out.println("name:"+text1.getText()+"\n"+"address:"+text2.getText());System.out.println("Qualification:"+JComboBox1.getSelectedItem());System.out.println("Hobby:");if(checkboxb1.isSelected()==true)System.out.print(checkboxb1.getText());if(checkboxb2.isSelected()==true)System.out.print(checkboxb2.getText());if(checkboxb3.isSelected()==true)System.out.print(checkboxb3.getText());System.out.println("\n"+"sex:");if(JRadioButton1.isSelected()==true)System.out.println(JRadioButton1.getText());if(JRadioButton2.isSelected()==true)System.out.println(JRadioButton2.getText());System.out.println("\n");}} private class Action2 implements ActionListener{public void actionPerformed(ActionEvent event){        text1.setText(null);text2.setText(null);checkboxb1.setSelected(false);checkboxb2.setSelected(false);checkboxb3.setSelected(false);ButtonGroup1.clearSelection();JComboBox1.setSelectedIndex(0);}}
}

  

重置后:

练习2:

package ShenF;import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;import javax.swing.JFrame;public class Main {public static void main (String args[]){Toolkit t=Toolkit.getDefaultToolkit();Dimension s=t.getScreenSize(); EventQueue.invokeLater(() -> {JFrame frame = new Main1();frame.setBounds(0, 0,(int)s.getWidth(),(int)s.getHeight());frame.setTitle("身份查询");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});        }
}

  

package ShenF;import java.awt.BorderLayout;
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.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Timer;
import javax.swing.*;public class Main1 extends JFrame {private static ArrayList<Person> Personlist;Scanner scanner = new Scanner(System.in);File file = new File("E:\\身份证号.txt");private JPanel Panel;private JLabel JLabel1;private JButton Button, Button2, Button3;private JTextArea text, text1, text2, text3;boolean tru = true;public Main1() {Panel = new JPanel();Panel.setLayout(null);Button = new JButton("1:按姓名字典序输出人员信息");Button2 = new JButton("2:查询最大年龄与最小年龄人员信息");Button3 = new JButton("查询相近年龄");JLabel1 = new JLabel("输入身份证号或者地址查询");JLabel1.setBounds(900, 50, 400, 30);text = new JTextArea(30, 80);text.setBounds(50, 180, 700, 700);text1 = new JTextArea(1, 30);text1.setBounds(900, 80, 400, 30);text2 = new JTextArea(30, 80);text2.setBounds(900, 180, 700, 700);text3 = new JTextArea(30, 80);text3.setBounds(420, 100, 200, 40);Button.addActionListener(new Action());Button.setBounds(50, 50, 300, 40);Button2.addActionListener(new Action1());Button2.setBounds(50, 100, 300, 40);Button3.addActionListener(new Action2());Button3.setBounds(650, 100, 120, 40);Panel.add(JLabel1);Panel.add(Button);Panel.add(Button2);Panel.add(Button3);Panel.add(text);Panel.add(text2);Panel.add(text1);Panel.add(text3);add(Panel);Timer timer = new Timer();TimerTask timeTask = new TimerTask() {@Overridepublic void run() {// TODO Auto-generated method stubtext2.setText(null);String place = text1.getText().toString().trim();for (int i = 0; i < Personlist.size(); i++) {String Str = (String) Personlist.get(i).getbirthplace();if (Str.contains(place) && !place.equals("")) {text2.append(Personlist.get(i).toString());}}for (int i = 0; i < Personlist.size(); i++) {String Str = (String) Personlist.get(i).getID();if (Str.contains(place) && !place.equals("")) {text2.append(Personlist.get(i).toString());}}}};timer.schedule(timeTask, 0, 100);Personlist = new ArrayList<>();try {FileInputStream fis = new FileInputStream(file);BufferedReader in = new BufferedReader(new InputStreamReader(fis));String temp = null;while ((temp = in.readLine()) != null) {Scanner linescanner = new Scanner(temp);linescanner.useDelimiter(" ");String name = linescanner.next();String ID = linescanner.next();String sex = linescanner.next();String age = linescanner.next();String place = linescanner.nextLine();Person Person = new Person();Person.setname(name);Person.setID(ID);Person.setsex(sex);int a = Integer.parseInt(age);Person.setage(a);Person.setbirthplace(place);Personlist.add(Person);}} catch (FileNotFoundException e) {System.out.println("查找信息失败");e.printStackTrace();} catch (IOException e) {System.out.println("信息读取有误");e.printStackTrace();}}private class Action implements ActionListener {public void actionPerformed(ActionEvent event) {text.setText(null);Collections.sort(Personlist);text.append(Personlist.toString());}}private class Action1 implements ActionListener {public void actionPerformed(ActionEvent event) {text.setText(null);int max = 0, min = 100;int j, k1 = 0, k2 = 0;for (int i = 1; i < Personlist.size(); i++) {j = Personlist.get(i).getage();if (j > max) {max = j;k1 = i;}if (j < min) {min = j;k2 = i;}}text.append("年龄最大:   " + Personlist.get(k1) + "\n" + "年龄最小:  " + Personlist.get(k2));}}private class Action2 implements ActionListener {public void actionPerformed(ActionEvent event) {text.setText(null);int a = Integer.parseInt(text3.getText().toString().trim());int d_value = a - Personlist.get(agenear(a)).getage();for (int i = 0; i < Personlist.size(); i++) {int p = Personlist.get(i).getage() - a;if (p == d_value || -p == d_value)text.append(Personlist.get(i).toString());}}}public static int agenear(int age) {int j = 0, min = 53, d_value = 0, k = 0;for (int i = 0; i < Personlist.size(); i++) {d_value = Personlist.get(i).getage() - age;if (d_value < 0)d_value = -d_value;if (d_value < min) {min = d_value;k = i;}}return k;}
}

  

package ShenF;public class Person implements Comparable<Person> {private String name;private String ID;private int age;private String sex;private String birthplace;public String getname() {return name;}public void setname(String name) {this.name = name;}public String getID() {return ID;}public void setID(String ID) {this.ID = ID;}public int getage() {return age;}public void setage(int age) {this.age = age;}public String getsex() {return sex;}public void setsex(String sex) {this.sex = sex;}public String getbirthplace() {return birthplace;}public void setbirthplace(String birthplace) {this.birthplace = birthplace;}public int compareTo(Person o) {return this.name.compareTo(o.getname());}public String toString() {return name + "\t" + sex + "\t" + age + "\t" + ID + "\t" + birthplace + "\n";}
}

  练习3:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Random;
import javax.swing.*;public class Text extends JFrame {JPanel p=new JPanel();JLabel timeLabel=new JLabel();JLabel[] label1=new JLabel[10];JLabel[] label2=new JLabel[10];JLabel[] label3=new JLabel[10];JLabel[] label4=new JLabel[10];JLabel[] label5=new JLabel[10];JTextField[] field=new JTextField[10];JLabel[] label6=new JLabel[10]; String[] btn_name= {"开始","重置","提交","重考"};JButton[] btn=new JButton[4];Panel2 panel2=null;int ExamCount=0;JLabel examLabel=new JLabel();double[] result=new double[10];public static void main(String[] args) {new Text("测试").setVisible(true);}public Text(String title) {setTitle(title);setLocationRelativeTo(null);setDefaultCloseOperation(3);setSize(400,500);setResizable(false);setForeground(Color.blue);add(new Panel1(),BorderLayout.NORTH);panel2=new Panel2();add(new JScrollPane(panel2));add(new Panel3(),BorderLayout.WEST);       }int rightResultCount=0;public void startExam() {int num1=0;int num2=0;String[] quots= {"+","-","*","/"};String quot=null;Random ran=null;ran=new Random(System.currentTimeMillis());Box box=Box.createVerticalBox();for(int i=0;i<10;i++) {num1=ran.nextInt(100)+1;num2=ran.nextInt(100)+1;int n=ran.nextInt(4);quot=new String(quots[n]);switch(quot) {case "+":result[i]=num1+num2;break;case "-":result[i]=num1-num2;break;case "*":result[i]=num1*num2;break;case "/":result[i]=num1/(num2*1.0);result[i]=Math.round(result[i]*100)/100.0;break;}label1[i]=new JLabel("第"+(i+1)+"题:");label2[i]=new JLabel(num1+"");label3[i]=new JLabel(quot);label4[i]=new JLabel(num2+"");label5[i]=new JLabel("=");field[i]=new JTextField();field[i].setPreferredSize(new Dimension(60,20));field[i].addKeyListener(new KeyAdapter() {public void keyTyped(KeyEvent ee) {if((ee.getKeyChar()>'9' || ee.getKeyChar()<'0') && ee.getKeyChar()!=45 && ee.getKeyChar()!='.') {ee.consume();}}});label6[i]=new JLabel("");  Box hbox=Box.createHorizontalBox();hbox.add(label1[i]);       hbox.add(Box.createHorizontalStrut(20));hbox.add(label2[i]);  hbox.add(Box.createHorizontalStrut(5));hbox.add(label3[i]); hbox.add(Box.createHorizontalStrut(5));hbox.add(label4[i]);     hbox.add(Box.createHorizontalStrut(5));hbox.add(label5[i]);   hbox.add(Box.createHorizontalStrut(5));hbox.add(field[i]);hbox.add(Box.createHorizontalStrut(20));hbox.add(label6[i]);box.add(hbox);box.add(Box.createVerticalStrut(20));}panel2.add(box);panel2.validate();}int submitCount=0;class Listener implements ActionListener{public void actionPerformed(ActionEvent e) {JButton button=(JButton)e.getSource();if(button==btn[0]) {startExam();ExamCount++;btn[0].setEnabled(false);for(int i=1;i<4;i++) {btn[i].setEnabled(true);}}if(button==btn[1]) {for(int i=0;i<10;i++) {field[i].setText("");}}if(button==btn[2] ) {rightResultCount=0;btn[2].setEnabled(false);double yourResult=0;for(int i=0;i<10;i++) {try {yourResult=Double.parseDouble(field[i].getText().trim());}catch(Exception ee) {}if(yourResult==result[i]) {rightResultCount++;label6[i].setText("V");label6[i].setForeground(Color.BLUE);}else {label6[i].setText("X");label6[i].setForeground(Color.RED);}}examLabel.setText("你答对了 "+rightResultCount+" 道题,答错了"+(10-rightResultCount)+" 道题!"+"考试得分是: "+rightResultCount*10+" 分!");}if(button==btn[3]) {btn[2].setEnabled(true);panel2.removeAll();startExam();ExamCount++;btn[3].setEnabled(false);for(int i=0;i<10;i++) {field[i].setText("");label6[i].setText("");}panel2.repaint();}if(btn[2].isEnabled()==false && btn[3].isEnabled()==false) {btn[1].setEnabled(false);}}}class Panel1 extends JPanel{public Panel1() {setPreferredSize(new Dimension(350,120));setLayout(new GridLayout(3,1,10,10));JTextArea area=new JTextArea("点击“开始”开始答题,答案中有小数的,保留2位!");area.setLineWrap(true);area.setEditable(false);add(area);add(examLabel);p.add(timeLabel);add(p);}}class Panel2 extends JPanel{public Panel2() {setPreferredSize(new Dimension(400,600));  }}class Panel3 extends JPanel{public Panel3() {setPreferredSize(new Dimension(50,100));setBackground(Color.LIGHT_GRAY);for(int i=0;i<4;i++) {btn[i]=new JButton(btn_name[i]);btn[i].addActionListener(new Listener());add(btn[i]);if(i>0) {btn[i].setEnabled(false);}}}}
}

  

实验总结:

一个学期的java学习已经结束,我发现相较于很多同学来说,我的能力还是不够,我还需比其他同学更加努力。而且我深刻的感到,很多学习是需要耐心和实践才能认识到自己的不足,才能不断完善的。在以后的学习里,我会继续深入学习,不断完善自己的知识面,学会活学活用。

还有对我帮助很多的老师和学长表示感谢。

意见和建议:

因为专业课较多,所以如果实验作业在周四下午发布,周天下午五点提交,在这之间时间比较紧张。

其次,我认为老师课堂教学+助教线上演示+网上教学+章末答疑这种教学方式很新颖也很有用,尤其是助教对我的帮助很大,因为我们在学习中遇到的问题,学长可能也经历过,所以能更好的解答,因为是同龄人,所以交流起来也更自然。还有每周提交完作业后,周一课上的答疑对我帮助也很大。觉得老师可以在以后的学妹学弟们身上继续使用这种教学方式,个人觉得很好。

转载于:https://www.cnblogs.com/Weiron/p/10199485.html

孔维滢《面向对象程序设计(java)》课程学习总结相关推荐

  1. 201771010110孔维滢面向对象程序设计(Java)第7周学习指导及要求

    学习目标 深入理解OO程序设计的特征:继承.多态: 熟练掌握Java语言中基于类.继承技术构造程序的语法知识: 利用继承定义类设计程序,能够设计开发含有1个主类.2个以上用户自定义类的应用程序. 实验 ...

  2. java日历程序设计,《面向对象程序设计》课程设计---java日历

    <面向对象程序设计>课程设计---java日历 软软 件件 学学 院院 课程设计课程设计报告书报告书 课程名称课程名称 面向对象程序设计课程设计面向对象程序设计课程设计 设计题目设计题目 ...

  3. 201771010118马昕璐《面向对象程序设计java》第八周学习总结

    第一部分:理论知识学习部分 1.接口 在Java程序设计语言中,接口不是类,而是对类的一组需求描述,由常量和一组抽象方法组成.Java为了克服单继承的缺点,Java使用了接口,一个类可以实现一个或多个 ...

  4. 计算机JAVA相关说课稿_面向对象程序设计-java说课稿

    面向对象程序设计-java说课稿 面向对象程序设计-JAVA说课稿,计算机系 毕景霞,目录,一.说教材 二.说教学目标 三.说重点难点 四.说教学方法 五.说教学内容 六.教学效果及总结,(一)教材的 ...

  5. 【Java】《面向对象程序设计——Java语言》Castle代码修改整理

    前言 最近闲来无事刷刷MOOC,找到以前看的浙大翁凯老师的<面向对象程序设计--Java语言>课程,重新过一遍仍觉受益颇深. 其中有一个Castle的例子,思路很Nice但代码很烂,翁凯老 ...

  6. java面向对象期末考试试题_《面向对象程序设计——java》期末考试试题2008a卷.doc...

    <面向对象程序设计--java>期末考试试题2008a卷.doc 还剩 6页未读, 继续阅读 下载文档到电脑,马上远离加班熬夜! 亲,喜欢就下载吧,价低环保! 内容要点: 第 7 页 共 ...

  7. 面向对象程序设计——Java语言 第3周编程题 查找里程(10分)

    面向对象程序设计--Java语言 第3周编程题 查找里程(10分) 题目内容 下图为国内主要城市之间的公路里程: 你的程序要读入这样的一张表,然后,根据输入的两个城市的名称,给出这两个城市之间的里程. ...

  8. java程序设计清考_面向对象程序设计(Java)-题库

    <面向对象程序设计(Java)-题库>由会员分享,可在线阅读,更多相关<面向对象程序设计(Java)-题库(33页珍藏版)>请在金锄头文库上搜索. 1.面向对象程序设计 (ja ...

  9. 孔维滢201771010110《面向对象程序设计(java)》第一周学习总结

    第一部分:课程准备部分 填写课程学习 平台注册账号 平台名称 注册账号 博客园:www.cnblogs.com Weiron 程序设计评测:https://pintia.cn/ 1135128361@ ...

  10. 201771010131孔维滢《面向对象程序设计(java)》第六周学习总结

    理论知识学习部分 类继承的格式: class  新类名  extends  已有类名(子类比超类拥有的功能更加丰富.) 继承层次:Java不支持多继承. 多态性:Java中,对象变量是多态的:不能把对 ...

最新文章

  1. sybase笔记 2762错误
  2. 可持久化链表(链式前向星)
  3. 简单的家庭无线路由设置
  4. 防火墙简介(二)——firewalld防火墙
  5. 数组的循环右移问题(好未来笔试题)
  6. 如何将cv::Mat类型转换为imgui中的ImTextureID类型
  7. 如何正确执行碎片整理或在群集共享卷(CSV)上使用CHKDSK命令
  8. java多线程之wait和notify协作,生产者和消费者
  9. 【对讲机的那点事】解读无管局《回答》:充分理解物联网产业诉求,值得点赞!...
  10. 软件需求工程 高校教学平台 测试计划
  11. linux 触摸屏多点触摸改成单点触摸 驱动调试
  12. 百度站长平台做https认证总是通不过,验证失败如何解决
  13. 致远oa mysql 安装_致远OA协同办公系统OA安装步骤.doc
  14. Excel如何过滤座机号提取出手机号码
  15. Spring-Cache
  16. 一文搞懂“正态分布”所有重要知识点
  17. Gensim库生成与导入W2V模型_CodingPark编程公园
  18. text/css什麼意思
  19. 衢州,“最多跑一次”的先行者
  20. 【Codeforces 723D】Lakes in Berland (dfs)

热门文章

  1. (7)椭圆的生成之中点画椭圆法
  2. java+vue+nodejs环境保护宣传网站设计与实现
  3. sql 如何快速复制一张表
  4. python读取word表格数据_python读取word表格数据库
  5. 一个华为离职者的离职感言,干货满满
  6. 海信电视访问电脑共享文件失败
  7. AEE运行机制深入剖析——阅读笔记
  8. python for item in items,python 字典item与iteritems的区别详解
  9. 【面试】旷视科技 - CV研究员
  10. 开发ASP.NET博客的第四步——用VS2005建立解决方案(二)(转)