




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 一一 课程设计的任务及要求课程设计的任务及要求 二二 需求分析需求分析 图形化界面 GUI 编程 编写一个图片浏览器程序可以支持 GIF JPEG jpeg TGA JPG jpg 等格式 单张打开图片 可以将同一目录下的图片按缩略图打开按 上一张 下一张 按钮可以显示相 应图片 运行 Applet 时 图像不是一气呵成的 因为方法不是吧图像完整的装 入内存再显示的 于此相反 方法创建一个线程 该线程与 Applet 的原有线程 并发执行 一边装入一边显示 从而产生上了不联需显示的现象 为了提高图 像才显示效果 可以采用双缓冲技术 首先把图像装入内存 然后再显示在屏 幕上 三三 设计思路设计思路 3 13 1 界面设计界面设计 选择图片按钮 主要用 dir 函数实现图片的遍历 上一张 下一张 通过做标轴回调函数实现 由于本软件为单机软件 不需要大量的数据读写和数据交换 实现上 下 功能要求只能读取 PictureBox 控件当前加载的目录 读取当前路径 创建一 维数组 frame newnew Frame PictureViewer Panel pb newnew Panel Button select newnew Button 选择图片 previous newnew Button 上一张 next newnew Button 下一张 select addActionListener thisthis previous addActionListener thisthis 3 2 3 2 图像加载图像加载 Applet 常用来显示储存在文件中的图像 多数 Applet 使用的是 GIF 或 JPEG 格式的图像文件 需 Applet 加载图像只需首先定义 Image 对象 然后使 用 getImage 方法把图像和文件结合起来即可 image width bi getWidth this image height bi getHeight this double image proportion 1 0 image height image width System out println image w image width h image height p1 image proportion 2 if image proportion screen proportion image height screen height image width int image height image proportion System out println p1 p0 w image width else image width screen width image height int image width image proportion System out println p0 p1 h image height 四四 详细设计详细设计 4 1 4 1 程序设计流程图程序设计流程图 4 2 4 2 源程序代码源程序代码 package C import java io File import java io FilenameFilter 开始 上一张 结束 图片 查找文件 查找文件 夹夹 查找盘符 图片 下一张 3 public class MyFilter implements FilenameFilter private String extension public MyFilter extension new String jpg JPG gif GIF png PNG jpeg JPEG public MyFilter String extension this extension extension public boolean accept File dir String name for String s extension if name endsWith s return true return false package C import java awt import java awt event import java awt image public class MyCanvas extends Canvas implements ComponentListener private static final long serialVersionUID 1L private BufferedImage bi private Image im private int image width private int image height public void setImage BufferedImage bi this bi bi this zoom public void paint Graphics g g drawImage im this getWidth image width 2 this getHeight image height 2 this 4 public void componentResized ComponentEvent e if bi null System out println resize this zoom this repaint public void componentMoved ComponentEvent e public void componentShown ComponentEvent e public void componentHidden ComponentEvent e public void zoom if bi null return int screen width this getWidth int screen height this getHeight double screen proportion 1 0 screen height screen width System out println screen w screen width h screen height p0 screen proportion image width bi getWidth this image height bi getHeight this double image proportion 1 0 image height image width System out println image w image width h image height p1 image proportion if image proportion screen proportion image height screen height image width int image height image proportion System out println p1 p0 w image width else image width screen width image height int image width image proportion System out println p0 p1 h image height im bi getScaledInstance image width image height Image SCALE SMOOTH packagepackage C importimport java awt 5 importimport java awt event importimport java awt image importimport java io importimport javax imageio publicpublic classclass T implementsimplements ActionListener privateprivate Frame frame privateprivate MyCanvas mc privateprivate String fpath privateprivate String fname privateprivate File files privateprivate intint findex privateprivate FileDialog fd load privateprivate MyFilter filter privateprivate Button previous privateprivate Button next publicpublic staticstatic voidvoid main String args throwsthrows Exception newnew T init publicpublic voidvoid init frame newnew Frame PictureViewer Panel pb newnew Panel Button select newnew Button 选择图片 previous newnew Button 上一张 next newnew Button 下一张 select addActionListener thisthis previous addActionListener thisthis next addActionListener thisthis pb add select pb add previous pb add next mc newnew MyCanvas mc setBackground newnew Color 200 210 230 mc addComponentListener mc frame add pb North frame add mc Center frame setSize 360 360 frame setLocation 400 200 frame addWindowListener newnew WindowAdapter publicpublic voidvoid windowClosing WindowEvent e System exit 0 frame setVisible truetrue thisthis validateButton 6 filter newnew MyFilter fd load newnew FileDialog frame 打开文件 FileDialog LOAD fd load setFilenameFilter filter publicpublic voidvoid actionPerformed ActionEvent e String command e getActionCommand ifif command equals 选择图片 fd load setVisible truetrue fpath fd load getDirectory fname fd load getFile ifif fpath nullnull files newnew File fpath listFiles filter thisthis setIndex elseelse ifif command equals 上一张 findex ifif findex files length findex files length 1 thisthis display files findex thisthis validateButton publicpublic voidvoid display File f trytry BufferedImage bi ImageIO read f mc setImage bi frame setTitle PictureViewer f getName catchcatch Exception e e printStackTrace mc repaint publicpublic voidvoid setIndex File current newnew File fpath fname ifif files nullnull forfor intint i 0 i 0 next setEnabled files nullnull 五五 运行调试与分析讨论运行调试与分析讨论 5 1 5 1 将同一目录下的图片按缩略图打开将同一目录下的图片按缩略图打开 5 2 5 2 单张打开图片单张打开图片 8 5 3 5 3 按按 上一张上一张 下一张下一张 按钮打开图片按钮打开图片 9 六六 设计体会与小结设计体会与小结 我通过这次编程实践学习到了 Image 和 Griphics 相关的类的使用 首先我通过网上搜集资料和自己看 jdk api 对 Image graphics swing 中 的类有了实质的操练 对它们的理解有了进一步的理解 不象以前只有模糊的 记忆 根本不会运用到实际的情况中 仅仅照着课本超代码 不过由于技术水 平限制 写的代码有点乱 类的层次不清晰 类之间的调用不明
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人防工程电气系统升级方案
- 老旧厂房内部管线改造与优化方案
- 教育培训内容生产质量保证措施
- 管网与污水处理厂衔接节点优化方案
- 城市老旧小区雨污分流改造施工方案
- 家庭诺如病毒预防清洁措施
- 港口工程环境保护管理体系和措施
- 老旧小区外立面整修施工团队组建与培训方案
- 桥梁跨河施工通航协调方案
- 文化建筑环保、消防、节水、节能措施
- 2025年浙江省杭州市杭州第二中学高考化学试题模拟训练试题含解析
- 小型公司合伙合同范本
- 老带新活动方案
- T-CAS 952-2024 基于荧光标记二抗的免疫组织化学检测 质量控制规范
- 企业员工健康管理方案
- 2025年福建省现场流行病学调查职业技能竞赛理论参考试题库(含答案)
- 2024国家安全教育大学生读本题库
- 样品确认流程培训
- 《基于管理需求下的酒店设计研究》
- 2025中国电信浙江公司社会招聘179高频重点提升(共500题)附带答案详解
- 外研版九年级上册英语Module 1~12全册教案(大单元教学设计)
评论
0/150
提交评论