⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myreader.java

📁 自己做的 见笑了 要是有高人来帮忙改进 不慎感激
💻 JAVA
字号:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class myreader implements ActionListener{
    private Frame f;
    private TextArea ta;
    FileDialog fd;
    
    public myreader(){
    	f=new Frame("File reader");
    	MenuBar mb=new MenuBar();
    	Menu m1=new Menu("文件");
    	MenuItem m11=new MenuItem("open");
    	MenuItem m12=new MenuItem("close");
    	m11.setActionCommand("open");
    	m12.setActionCommand("exit");
    	m11.addActionListener(this);
    	m12.addActionListener(this);
    	m1.add(m11);
    	m1.addSeparator();
    	m1.add(m12);
    	
    	Menu m2=new Menu("编辑");
    	MenuItem m21=new MenuItem("undo");
    	MenuItem m22=new MenuItem("copy");
    	MenuItem m23=new MenuItem("paste");
    	m21.setActionCommand("back");
    	m22.setActionCommand("copy");
    	m23.setActionCommand("paste");
    	m2.add(m21);
    	m21.addActionListener(this);
    	m22.addActionListener(this);
    	m23.addActionListener(this);
    	m2.add(m22);
    	m2.addSeparator();
    	m2.add(m23);
    	
    	mb.add(m1);
    	mb.add(m2);
    	f.setMenuBar(mb);
    	
    	ta=new TextArea();
    	f.add(ta);
    	f.addWindowListener(new WindowAdapter(){
    		public void windowClosing(WindowEvent e){
    			System.exit(1);
    		}
    	});
    	f.setSize(400,400);
    	f.setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e){
    	String s=e.getActionCommand();
    	if (s.equals("open")){
    		fd=new FileDialog(f,"文件对话筐",FileDialog.LOAD);
    		fd.setVisible(true);
    		String fpath=fd.getDirectory();
    		String fname=fd.getFile();
    		String file=fpath+fname;
    		this.outputFile(file);//调用函数输出文件内容
    	}
    	else if(s.equalsIgnoreCase("exit")){
    		System.exit(1);
    	}
    	//m2 菜单还没有实现  undo copy paste 不能有功能实现
    }
    //文件内容输出函数
    public void outputFile(String file){
    	try{
    		FileReader fr=new FileReader(file);
    		BufferedReader br=new BufferedReader(fr);
    		String d=br.readLine();
    		while(d!=null){
    			ta.append(d);
    			ta.append("\n");
    			d=br.readLine();
    			
    		}
    		br.close();
    		f.setTitle(file);
    	}catch (FileNotFoundException el){
    		el.printStackTrace();
    		
    	}catch(IOException e2){
    		e2.printStackTrace();
    	}
    }
    public static void main(String args[]){
    	new myreader();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -