为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

java文件查看器

2017-10-15 13页 doc 43KB 47阅读

用户头像

is_954223

暂无简介

举报
java文件查看器java文件查看器 本文由361589065贡献 doc文档可能在WAP端浏览体验不佳。建议您优先选择TXT,或下载源文件到本机查看。 //ImageViewer.java package wenjianchakanqi; import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.filechooser.FileFilter; import java.aw...
java文件查看器
java文件查看器 本文由361589065贡献 doc文档可能在WAP端浏览体验不佳。建议您优先选择TXT,或下载源文件到本机查看。 //ImageViewer.java package wenjianchakanqi; import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.filechooser.FileFilter; import java.awt.image.*; import java.awt.geom.AffineTransform; import java.io.*; import java.util.ArrayList; import java.awt.image.ConvolveOp; import java.awt.Point; import java.awt.geom.*; public class ImageViewer extends JFrame { private Image img; private JButton button1,button2,button3,button4,button5,button6,button7,button8; private JPanel panel; Container c; DrawPanel dp; public boolean start=false; public int flag=0; String name="c:\\aa.jpg"; public ImageViewer() { super("ImageViewer"); c=getContentPane(); panel=new JPanel(); dp=new DrawPanel(name); c.add(dp,BorderLayout.CENTER); final MouseHandler handler=new MouseHandler(dp); dp.addMouseMotionListener(handler); dp.addMouseListener(handler); button1=new JButton("打开"); panel.add(button1); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser=new JFileChooser(); chooser.setCurrentDirectory(new File(".")); final ExtensionFileFilter filter=new ExtensionFileFilter(); filter.addExtension("jpg"); filter.addExtension("jpeg"); filter.addExtension("gif"); filter.setdescription("Image Files"); chooser.setFileFilter(filter); int result=chooser.showOpenDialog(dp); if(result==JFileChooser.APPROVE_OPTION) { name=chooser.getSelectedFile().getPath(); getContentPane().remove(dp); removeMouseListener(handler); dp = new DrawPanel(name); getContentPane().add(dp, BorderLayout.CENTER); MouseHandler handler=new MouseHandler(dp); dp.addMouseMotionListener(handler); dp.addMouseListener(handler); dp.revalidate(); } } }); button2=new JButton("缩放"); panel.add(button2); button2.addActionListener(new Handler2()); button3=new JButton("翻转"); panel.add(button3); button3.addActionListener(new Handler3()); button4=new JButton("移动"); panel.add(button4); button4.addActionListener(new Handler4()); button5=new JButton("还原"); panel.add(button5); button5.addActionListener(new Handler5()); button6=new JButton("边缘"); panel.add(button6); button6.addActionListener(new Handler6()); button7=new JButton("画图"); panel.add(button7); button7.addActionListener(new Handler7()); button8=new JButton("退出"); panel.add(button8); button8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); c.add(panel,BorderLayout.SOUTH); setSize(550,350); show(); } private class Handler2 implements ActionListener { public void actionPerformed(ActionEvent e) { String str=JOptionPane.showInputDialog(null,"Please input zoom factor","Message",1); System.out.println(str); if((str==null)||(str.length()==0)) JOptionPane.showMessageDialog(null,"The data cannot be null","Message",1); else dp.zoom(Double.parseDouble(str)); } } private class Handler3 implements ActionListener { public void actionPerformed(ActionEvent e) { String str=JOptionPane.showInputDialog(null,"Please input flip angle","Message",1); if((str==null)||(str.length()==0)) JOptionPane.showMessageDialog(null,"The data cannot be null","Message",1); else dp.rotate(Integer.parseInt(str)); } } private class Handler4 implements ActionListener { public void actionPerformed(ActionEvent e) { dp.flag=3; } } private class Handler5 implements ActionListener { public void actionPerformed(ActionEvent e) { dp.OriginalImage(); } } private class Handler6 implements ActionListener { public void actionPerformed(ActionEvent e) { dp.Edge(); } } private class Handler7 implements ActionListener { public void actionPerformed(ActionEvent e) { dp.flag=5; } } private static class ExtensionFileFilter extends FileFilter { private String description=""; private ArrayList extensions=new ArrayList(); public void addExtension(String extension) { if(!extension.startsWith(".")) extension="."+extension; extensions.add(extension.toLowerCase()); } public void setdescription(String aDescription) { description=aDescription; } public String getDescription() { return description; } public boolean accept(File f) { if(f.isDirectory()) return true; String name=f.getName().toLowerCase(); for(int i=0;i格式
"); about=new JMenu("关于"); exfunction=new JMenu("特殊功能"); //about.addActionListener(this); file1=new JMenuItem("打开"); file1.addActionListener(this); file2=new JMenuItem("退出"); file2.addActionListener(this); file3=new JMenuItem("清空"); file3.addActionListener(this); zuozhe=new JMenuItem("作者"); zuozhe.addActionListener(this); xinjian=new JMenuItem("新建"); xinjian.addActionListener(this); copy=new JMenuItem("复制"); copy.addActionListener(this); paste=new JMenuItem("粘贴"); paste.addActionListener(this); cut=new JMenuItem("剪切"); cut.addActionListener(this); pic=new JMenuItem("图片查看"); pic.addActionListener(this); pop = new JPopupMenu(); t.addMouseListener(new MouseAdapter(){ }); pop.add(copy); pop.add(paste); pop.add(cut); file.add(file1); file.add(file2); file.add(xinjian); edit.add(file3); edit.add(copy); edit.add(paste); edit.add(cut); about.add(zuozhe); exfunction.add(pic); menubar.add(file); menubar.add(edit); menubar.add(about); menubar.add(exfunction); this.add(pop); p.setLayout(new GridLayout(1,1)); setJMenuBar(menubar); p.add(s); add(p); setSize(500,500); setVisible(true); show(); } @SuppressWarnings("deprecation") protected static void setClipboardText(Clipboard clip, String writeMe) { Transferable tText = new StringSelection(writeMe); clip.setContents(tText, null); } protected static String getClipboardText(Clipboard clip) throws Exception{ // 获取剪切板中的内容 Transferable clipT = clip.getContents(null); if (clipT != null) { // 检查内容 是否是文本类型 if (clipT.isDataFlavorSupported(DataFlavor.stringFlavor)) return (String)clipT.getTransferData(DataFlavor.stringFlavor); } return null; } public void save(String filename){ JFrame f=new JFrame("FileDialog"); FileDialog d; d=new FileDialog(f,"FileDialog"); d.setVisible(true); //String filename=d.getFile(); // File openf=new File(filename); try { RandomAccessFile fw=new RandomAccessFile(d.getDirectory()+filename,"rw"); String s=t.getText(); fw.writeChars(s); fw.close(); }catch(Exception er){} } public void actionPerformed(ActionEvent e){ // byte b[]=new byte[888]; if (e.getActionCommand() == "打开") { fd = new FileDialog(this, "打开", FileDialog.LOAD); fd.setDirectory("."); fd.show(); File myfile = new File(fd.getDirectory(), fd.getFile()); if (!myfile.getName().endsWith(".txt")) { JOptionPane.showMessageDialog(null, " 文 件 类 型 错 误 ", JOptionPane.ERROR_MESSAGE); } else { BufferedReader br=null; InputStreamReader isr = null; try { isr = new InputStreamReader(new FileInputStream(myfile)); br = new BufferedReader(isr); //RandomAccessFile raf=new RandomAccessFile(myfile,"r"); String temp; while ((temp = br.readLine()) != null) { " 错 误 ", t.append(temp + "\n"); } } catch (IOException ex) { Logger.getLogger(MyCompiler.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if(br!=null){ br.close(); } isr.close(); } catch (IOException ex) { Logger.getLogger(MyCompiler.class.getName()).log(Level.SEVERE, null, ex); } } } } if (e.getActionCommand()== "退出") { dispose(); System.exit(0); } if (e.getActionCommand() == "清空") { t.getAccessibleContext().getAccessibleEditableText().setTextContents(""); } if(e.getActionCommand() == "作者") { JOptionPane.showConfirmDialog(null," 作 者 : 殷 振 振 "," 作 者 信 息 ",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE); //JOptionPane.showMessageDialog(null, "作者:殷振振", "作者信息", ABORT); } if (e.getActionCommand() == "新建"){ JFrame aFrame=new JFrame(); aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JOptionPane optionPane=new JOptionPane(); String choices[]={"是","否","取消"}; int n=optionPane.showOptionDialog(aFrame,"文件正文已更改,是否保存更改","文本 编 辑 器 ",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,choices, choices[0]); //保存文件后新建 if(n==0){//若文件存在,保存在原文件中,再新建文件 try{ if(VFmyFile.exists()){ save(VSmyFileName); // call the save founction t.setText(""); VIindex++; } else{//若文件不存在,则保存后再新建 myFDlg=new FileDialog(myfrm,"保存文件",FileDialog.SAVE); myFDlg.setFile(VSmyFileName); myFDlg.show(); VSmyFileName=myFDlg.getDirectory()+myFDlg.getFile(); // save(VSmyFileName); t.setText(""); VIindex++; } } catch(Exception ne){} } //不保 存文件新建 if(n==1){ t.setText(""); VIindex++; } //取消新建 if(n==0){return;} } if(e.getActionCommand() =="复制"){ String temp=t.getSelectedText(); //拖动鼠标选 取文本。 StringSelection text=new StringSelection(temp); clipboard.setContents(text,null); } if(e.getActionCommand() =="粘贴 "){ Transferable contents=clipboard.getContents(this); DataFlavor flavor= DataFlavor.stringFlavor; if( contents.isDataFlavorSupported(flavor)) try{ String str; str=(String)contents.getTransferData(flavor); t.append(str); } catch(Exception ee){} } if(e.getActionCommand() =="剪切"){ String temp=t.getSelectedText(); //拖动鼠标选取文本。 StringSelection text=new StringSelection(temp); clipboard.setContents(text,null); int start=t.getSelectionStart(); int end =t.getSelectionEnd(); t.replaceRange("",start,end) ; } if(e.getActionCommand() =="图片查看"){ ImageViewer img= new ImageViewer(); img.setVisible(true); //img.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } } } 1
/
本文档为【java文件查看器】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索