图片浏览器(后面附有完整代码)一、需求分析1、首先。因为要显示图片所以要先有一个界面;用JFrame;2、因为要能显示选定文件夹内的图片,所以要有一个文件夹选择器;用JTree;3、显示图片的滚动面板;用JScrollPane;4、因为要对图片进行分类,所以要设计分类模块;5、因为要对图片进行备份,所以要设计备份模块;6、因为要对图片进行幻灯播放,所以要设计幻灯播放模块;二、概要设计本次课程设计模块图、系统流程图:三、运行环境、开发语言操作系统:WindowsXP专业版32位SP3(DirectX9.0c)开发工具:MyEclipse开发语言:java四、详细设计幻灯片播放分类备份文件选择地点JTree文件选择器相册任务其它备份还原暂停播放开始播放继续播放1程序清单Stringpt;鼠标点击的图片的绝对路径File[]files2;面板上正在显示的图片文件JLabel[]imageLabel;图片绑定的JLabel控件组JLabeljlabel,jimageLabel;图片绑定的JLabel控件JPaneljp1,jp2,jp3;显示不同内容的面板JButton[]jb;按钮数组privateJTreetree;文件夹选择树privateJScrollPanejsp1,jsp2,jsp3;滚动面板Timertimer;计时器publicPictureDir()类的构造函数WindowAction窗体事件TreeSelect文件夹选择树事件FileDidianListener分类为地点事件FileRenwuListener分类为人物事件FileXiangceListener分类为相册事件FileQitaListener分类为其它事件FileZipListener备份事件FileBackListener还原事件MouseAction鼠标点击事件FileStartListener幻灯片播放事件JCAction显示分类图片事件read(String)读文件函数save(String,String)写文件函数unzip(String,String)解压缩函数resizeIcon(ImageIcon,JLabel)控制图片显示大小的函数deleteFile(File)删除文件函数main(String[])主函数2主要代码整个程序的界面如下图:2.1选择文件夹功能classTreeSelectimplementsTreeSelectionListener{publicvoidvalueChanged(TreeSelectionEvente){TreePathpath=e.getPath();DefaultMutableTreeNodenode=(DefaultMutableTreeNode)path.getLastPathComponent();ObjectuserObject=node.getUserObject();if(!(userObjectinstanceofFile)){return;}Filefolder=(File)userObject;if(!folder.isDirectory())return;File[]files1=initImageSets1(folder);for(Filefile:files1){node.add(newDefaultMutableTreeNode(file));}files2=initImageSets2(folder);for(inti=0;iimageLabel.length;i++){imageLabel[i].setIcon(null);imageLabel[i].setBorder(null);}for(inti=0;ifiles2.length;i++){imageLabel[i].setIcon(newImageIcon(files2[i].toString()));imageLabel[i].addMouseListener(newMouseAction());imageLabel[i].setName(String.valueOf(i));resizeIcon(newImageIcon(files2[i].toString()),imageLabel[i]);}}privateFile[]initImageSets1(FilepictureDir){returnpictureDir.listFiles(newFilenameFilter(){publicbooleanaccept(Filedir,Stringname){if(!newFile(dir,name).isFile())returntrue;elsereturnfalse;}});}privateFile[]initImageSets2(FilepictureDir){returnpictureDir.listFiles(newFilenameFilter(){publicbooleanaccept(Filedir,Stringname){if(!newFile(dir,name).isFile())returnfalse;StringlowserName=name.toLowerCase();if(lowserName.endsWith(jpg)||lowserName.endsWith(jpeg)||lowserName.endsWith(gif)||lowserName.endsWith(png)||lowserName.endsWith(GIF)||lowserName.endsWith(TIFF)||lowserName.endsWith(ICO)||lowserName.endsWith(BMP)){returntrue;}returnfalse;}});}}结果:2.2图片分类功能classFileDidianListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){try{save(pt,didian.txt);JOptionPane.showMessageDialog(null,分类为“地点”完成!);}catch(Exceptione1){e1.printStackTrace();}}}classFileRenwuListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){try{save(pt,renwu.txt);JOptionPane.showMessageDialog(null,分类为“人物”完成!);}catch(Exceptione1){e1.printStackTrace();}}}privateDefaultMutableTreeNoderootNode;classFileXiangceListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){try{save(pt,xiangce.txt);JOptionPane.showMessageDialog(null,分类为“相册”完成!);}catch(Exceptione1){e1.printStackTrace();}}}classFileQitaListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){try{save(pt,qita.txt);JOptionPane.showMessageDialog(null,分类为“其它”完成!);}catch(Exceptione1){e1.printStackTrace();}}}结果:2.3图片备份和还原功能classFileZipListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){try{inta=0;Filefile1=newFile(pt);Filefile2=newFile(imagesdata.zip);Filef=newFile(D:/1/3/5);f.mkdirs();if(!file2.exists()){file2.createNewFile();a=1;}elseunzip(imagesdata.zip,D:/1/3/5);FileOutputStreamfos=newFileOutputStream(file2);ZipOutputStreamzos=newZipOutputStream(fos);byte[]buffer=newbyte[1024];if(a==0){File[]files=f.listFiles();File[]filess=newFile[files.length+1];for(inti=0;ifiles.length;i++){filess[i]=files[i];}filess[filess.length-1]=file1;for(inti=0;ifiless.length;i++){String[]st=filess[i].getName().split(.);for(intj=0;jst.length;j++){JOptionPane.showMessageDialog(null,j+=+st[j]);}ZipEntryentry=newZipEntry(newDate().getTime()+filess[i].getName());FileInputStreamin=newFileInputStream(filess[i]);zos.putNextEntry(entry);intlen;while((len=in.read(buffer))0){zos.write(buffer,0,len);}zos.closeEntry();in.close();}}if(a==1){ZipEntryentry=newZipEntry(newDate().getTime()+file1.getName());FileInputStreamfis=newFileInputStream(file1);zos.putNextEntry(entry);intread=0;while((read=fis.read(buffer))!=-1){zos.write(buffer,0,read);}zos.closeEntry();fis.close();}zos.close();fos.close();JOptionPane.showMessageDialog(null,备份完成!);deleteFile(f);}catch(Exceptione1){e1.printStackTrace();JOptionPane.showMessageDialog(null,备份失败!);Filef=newFile(D:/1/2/3);deleteFile(f);}}}classFileBackListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){JFileChooserchooser1;chooser1=newJFileChooser();chooser1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);chooser1.setCurrentDirectory(newFile(.));intresult=chooser1.showOpenDialog(newJFrame());Filefile=chooser1.getSelectedFile();if(