




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
福建农林大学计算机与信息学院(程序设计类课程)实验报告课程名称:JAVA语言程序设计姓 名:系:计算机专 业:计算机科学与技术年 级:09级学 号:指导教师:职 称:年 月 日实验项目列表序号实验项目名称成绩指导教师1实验一 Control Statements2实验二Array3实验三Classes and Objects4实验四Inheritance and Polymorphism5实验五GUI Programming6789101112福建农林大学计算机与信息学院实验报告系(教研室): 计算机 专业: 计算机科学与技术 年级: 09级 实验课程: 姓名: 学号: 实验室号:_ 计算机号: 实验时间: 2012.5.16 指导教师签字: 成绩: 实验名称 GUI Programming一、实验目的和要求实验目的1.Grasp the usage of GUIcomponent2.Understand the designing of GUI event-driving programming3.Understand MVC(Model-View-Controller)model实验要求利用类图、状态图等去描述系统,理解面对对象的建模过程,体会设计模式对软件设计的意义。二、实验内容和原理采用MVC的方式重新实现地址薄维护程序。界面如图1所示:图1 地址薄应用程序的用户界面MVC三者之间的关系可参考图2。视图类AddressBookJFrame中的方法setAddress用于将参数的值在界面上显示,而方法getAddress()用于将界面上的值生成一个Address类型的对象。在控制器AddressBookController中有相应的实现了ActionListerner接口的类(如图3),用来侦听视图中相应命令按钮的事件,视图中的一类add方法(如addAddActionListerner)用于注册侦听器。对模型,书中的例子是用随机访问文件,你可以使用数据库,通过JDBC建立与数据库的连接;也可以用顺序文本文件,先把文件读入到一个Collection(如ArrayList)中,再在从集合上读指定位置记录,或者把记录添加到集合中,最后再把集合中的数据写入文件中。图2是模型-视图-控制器参考实现图图2 模型-视图-控制器参考实现图图3是侦听Add按钮和First按钮的侦听器例 class AddActionListener implements ActionListener public void actionPerformed(ActionEvent e) Address address; try address = addressBookJFrame.getAddress(); addressBookModel.writeAddress(address); catch (IOException ex) ex.printStackTrace(); class FirstActionListener implements ActionListener public void actionPerformed(ActionEvent e) Address address; try address = addressBookModel.readFirst(); addressBookJFrame.setAddress(address); catch (IOException ex) ex.printStackTrace(); 图3 侦听Add按钮和First按钮的侦听器例三、实验环境eclipse四、算法描述及实验步骤1、Edit the Java program;2、Compile Java program,find the syntactic errors in the program, record the main errors and correct them;3、Test the program using the pre-designed test case, find the logical errors in the program and correct them;4、Run the final program, and analyze the results。五、调试过程1人工检查2上机调试3改正语法错误4运行结果六、实验结果七、总结由于对于GUI这块的不熟悉,这次实验并没有太多的收获,仅作了解附录:package GUIProgramming;import java.io.*;public class FixedLengthStringIO /* Read fixed number of characters from a DataInput stream */ public static String readFixedLengthString(int size, DataInput in) throws IOException / Declare an array of characters char chars = new charsize; / Read fixed number of characters to the array for (int i = 0; i size; i+) charsi = in.readChar(); return new String(chars); /* Write fixed number of characters to a DataOutput stream */ public static void writeFixedLengthString(String s, int size, DataOutput out) throws IOException char chars = new charsize; / Fill in string with characters s.getChars(0, Math.min(s.length(), size), chars, 0); / Fill in blank characters in the rest of the array for (int i = Math.min(s.length(), size); i 0) readAddress(0); catch (IOException ex) ex.printStackTrace(); ); jbtNext.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) try long currentPosition = raf.getFilePointer(); if (currentPosition 0) / Why 2 * 2 * RECORD_SIZE? See the follow-up remarks readAddress(currentPosition - 2 * 2 * RECORD_SIZE); else readAddress(0); catch (IOException ex) ex.printStackTrace(); ); jbtLast.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) try long lastPosition = raf.length(); if (lastPosition 0) / Why 2 * RECORD_SIZE? See the follow-up remarks readAddress(lastPosition - 2 * RECORD_SIZE); catch (IOException ex) ex.printStackTrace(); ); / Display the first record if exists try if (raf.length() 0) readAddress(0); catch (IOException ex) ex.printStackTrace(); /* Write a record at the end of the file */ public void writeAddress() try raf.seek(raf.length(); FixedLengthStringIO.writeFixedLengthString( jtfName.getText(), NAME_SIZE, raf); FixedLengthStringIO.writeFixedLengthString( jtfStreet.getText(), STREET_SIZE, raf); FixedLengthStringIO.writeFixedLengthString( jtfCity.getText(), CITY_SIZE, raf); FixedLengthStringIO.writeFixedLengthString( jtfState.getText(), STATE_SIZE, raf); FixedLengthStringIO.writeFixedLengthString( jtfZip.getText(), ZIP_SIZE, raf); catch (IOException ex) ex.printStackTrace(); /* Read a record at the specified position */ public void readAddress(long position) throws IOException raf.seek(position); String name = FixedLengthStringIO.readFixedLengthString( NAME_SIZE, raf); String street = FixedLengthStringIO.readFixedLengthString( STREET_SIZE, raf); String city = FixedLengthStringIO.readFixedLengthString( CITY_SIZE, raf); String state = FixedLengthStringIO.readFixedLengthString( STATE_SIZE, raf); String zip = FixedLengthStringIO.readFixedLengthString( ZIP_SIZE, raf); jtfName.setText(name); jtfStreet.setText(street); jtfCity.setText(city); j
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 骨科四肢创伤术后护理
- 物业经理年终总结
- 网络广告投放合同(样式三)7篇
- 运营类工作汇报
- 腰椎结核病历汇报
- 缺氧性脑病的护理查房
- 全职助理合同5篇
- 公司环卫安全培训课件
- 黑龙江省2025年全国成人高等学校招生统一考试数学(文)复习题库及答案
- 黑龙江省2025年全国成人高等学校招生统一考试英语(高起点)综合练习题及答案
- 燃气运营安全管理方案
- 2025-2026学年粤教粤科版(2024)小学科学二年级上册(全册)教学设计(附目录)
- 查冻扣业务知识公安机关等执法单位相关试题试卷
- 济南战役教学课件
- 小学生班干部竞选
- 2025年秋教科版(2024)小学科学三年级上册教学计划及教学进度表(第一学期)
- 妇科外阴解剖学课件
- 2025四川省水电投资经营集团有限公司所属电力公司员工招聘6人考试模拟试题及答案解析
- 安置协议转让合同范本
- 2025年经济师职称考试经济基础模拟卷:反垄断法基础知识试题
- 2025年生态环境综合行政执法考试参考题库(附答案)
评论
0/150
提交评论