ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:345.70KB ,
资源ID:4996140      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4996140.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java课程设计的图片浏览器的原代码.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java课程设计的图片浏览器的原代码.docx

1、Java课程设计的图片浏览器的原代码一.课程设计的任务及要求任务:图形化界面(GUI)编程,编写一个图片浏览器程序1.1 可以单张打开图片1.2 可以将同一目录下的图片按缩略图打开1.3 按“上一张”“下一张”按钮可以显示相应图片二.需求分析图形化界面(GUI)编程,编写一个图片浏览器程序可以支持“.GIF”, “.JPEG”,“.jpeg”,“.TGA”,“.JPG”,“.jpg”等格式,单张打开图片,可以将同一目录下的图片按缩略图打开按“上一张”“下一张”按钮可以显示相应图片。运行Applet时,图像不是一气呵成的,因为方法不是吧图像完整的装入内存再显示的。于此相反,方法创建一个线程,该线

2、程与Applet的原有线程并发执行,一边装入一边显示,从而产生上了不联需显示的现象。为了提高图像才显示效果,可以采用双缓冲技术:首先把图像装入内存,然后再显示在屏幕上。三. 设计思路3.1界面设计选择图片按钮:主要用dir函数实现图片的遍历。上一张,下一张:通过做标轴回调函数实现。由于本软件为单机软件,不需要大量的数据读写和数据交换,实现上、下功能要求只能读取PictureBox控件当前加载的目录,读取当前路径,创建一维数组。frame = new Frame(PictureViewer); Panel pb = new Panel(); Button select = new Button(

3、选择图片); previous = new Button(上一张); next = new Button(下一张); select.addActionListener(this); previous.addActionListener(this);3.2.图像加载:Applet常用来显示储存在文件中的图像,多数Applet使用的是GIF或JPEG格式的图像文件。需Applet加载图像只需首先定义Image对象,然后使用getImage()方法把图像和文件结合起来即可。image_width = bi.getWidth(this); image_height = bi.getHeight(thi

4、s); 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( p1p0 w= +i

5、mage_width); else image_width = screen_width; image_height = (int)(image_width * image_proportion); System.out.println( p0p1 h= +image_height); 四.详细设计4.1.程序设计流程图4.2.源程序代码package C;import java.io.File;import java.io.FilenameFilter;public class MyFilter implements FilenameFilter private String extensi

6、on; 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.*

7、; 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(BufferedI

8、mage 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); public void componentResized(ComponentEvent e) if(bi != null) System.out.println(resize!); this.zoom(); this.repaint(); public void componentMoved

9、(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.p

10、rintln(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_pro

11、portion screen_proportion) image_height = screen_height; image_width = (int)(image_height / image_proportion); System.out.println( p1p0 w= +image_width); else image_width = screen_width; image_height = (int)(image_width * image_proportion); System.out.println( p0p1 h= +image_height); im = bi.getScal

12、edInstance(image_width,image_height,Image.SCALE_SMOOTH); package C;import java.awt.*;import java.awt.event.*;import java.awt.image.*;import java.io.*;import javax.imageio.*;public class T implements ActionListener private Frame frame; private MyCanvas mc ; private String fpath; private String fname;

13、 private File files; private int findex ; private FileDialog fd_load; private MyFilter filter; private Button previous ; private Button next ; public static void main( String args) throws Exception new T().init(); public void init() frame = new Frame(PictureViewer); Panel pb = new Panel(); Button se

14、lect = new Button(选择图片); previous = new Button(上一张); next = new Button(下一张); select.addActionListener(this); previous.addActionListener(this); next.addActionListener(this); pb.add(select); pb.add(previous); pb.add(next); mc = new MyCanvas(); mc.setBackground(new Color(200,210,230); mc.addComponentLi

15、stener(mc); frame.add(pb,North); frame.add(mc,Center); frame.setSize(360,360); frame.setLocation(400,200); frame.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); frame.setVisible(true); this.validateButton(); filter = new MyFilter(); fd_load = new Fil

16、eDialog(frame,打开文件,FileDialog.LOAD); fd_load.setFilenameFilter(filter); public void actionPerformed(ActionEvent e) String command = e.getActionCommand(); if(command.equals(选择图片) fd_load.setVisible(true); fpath = fd_load.getDirectory(); fname = fd_load.getFile(); if(fpath != null) & (fname != null) t

17、his.display(new File(fpath + fname); files = new File(fpath).listFiles(filter); this.setIndex(); else if(command.equals(上一张) findex-; if(findex= files.length) findex = files.length-1; this.display(filesfindex); this.validateButton(); public void display(File f) try BufferedImage bi = ImageIO.read(f)

18、; mc.setImage(bi); frame.setTitle(PictureViewer - + f.getName() + ); catch(Exception e) e.printStackTrace(); mc.repaint(); public void setIndex() File current = new File(fpath + fname); if(files != null) for(int i=0;i 0); next.setEnabled(files!=null) & (findex(files.length-1); 五.运行调试与分析讨论5.1.将同一目录下的

19、图片按缩略图打开 5.2.单张打开图片 5.3.按”上一张”,”下一张”按钮打开图片六. 设计体会与小结我通过这次编程实践学习到了Image和Griphics相关的类的使用。首先我通过网上搜集资料和自己看jdk api对Image、graphics、swing中的类有了实质的操练,对它们的理解有了进一步的理解。不象以前只有模糊的记忆,根本不会运用到实际的情况中,仅仅照着课本超代码。不过由于技术水平限制,写的代码有点乱,类的层次不清晰。类之间的调用不明朗。程序中的代码出现累赘,重复创建实例,浪费系统资源。这是很早的了,现在我修改了里面的一些如:如果图片文件中有不是图片格式的他不会显示,我让它自动

20、跳过去。还有当图片到达文件末尾,上下页按钮不能用并给出提示。改观了软件的外观,稍微美观了些通过该课程设计,使我们掌握了程序设计的基本思路和方法,并使我们巩固和提高了java编程技术。通过完成具有一定难度的课程设计题目的编写,调试运行工作,使我们进一步掌握了面向对象程序设计的基本方法和编译技巧,巩固所学的理论知识,使理论与实际相结合,从而提高自我分析问题 ,和解决问题的 能力。培养研发和独立分析以及独立设计的能力 。具备初步的独立分析和设计能力;软件开发过程得问题分析,系统设计,程序编码,测试等基本方发和技巧;综合运用所学的理论知识和方法进行独立分析和解决问题的能力。 而且在这次设计中,把死板的课本知识变得生动有趣,激发了学习的积极性, 强化了所学的知识。把课堂上的知识通过自己设计的程序表示出来,加深了对理论知识的理解。 通过本次课程设计,我们还学到了不少动手实践的经验,对以后的学习,工作都是很有用的。七.设计的主要参考文献(1)丁振凡.Java语言实用教程北京邮电大学出版社 (2)耿祥义.Java2实用教程清华大学出版社(3)赵付青.Java面向对象程序设计国防工业出版社.(4)耿祥义.Java课程设计清华大学出版社

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1