文本文档.java无法编辑_简单的文本 编辑器。可以保存txt文档,但是不能打开txt文档...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

public class B8_8 extends JFrame implements ActionListener{

JMenuBar menu;

JMenu menu1,menu2;

JMenuItem menuSe2,menuSe3;

JTextArea textArea;

public static void main(String[] args) {

B8_8 bb=new B8_8();

}

public B8_8(){

menu=new JMenuBar();

menu1=new JMenu("文件(F)");

menu1.setMnemonic('F');//设置当前模型上的键盘助记符

menu2=new JMenu("编辑(E)");

menu2.setMnemonic('E');

menuSe2=new JMenuItem("打开",new ImageIcon("E:/1.jpg"));

menuSe2.addActionListener(this);

menuSe2.setActionCommand("open");

menuSe3=new JMenuItem("保存",new ImageIcon("E:/2.jpg"));

menuSe3.addActionListener(this);

menuSe3.setActionCommand("save");

textArea=new JTextArea();

menu1.add(menuSe2);menu1.add(menuSe3);

menu.add(menu1);menu.add(menu2);

this.setJMenuBar(menu);this.add(textArea);

ImageIcon tp1=new ImageIcon("E:/壁纸/1.jpg");

this.setIconImage(tp1.getImage());

this.setTitle("记事本");

//mb=new Mymb6();

//this.add(mb);

//this.addWindowListener(mb);

this.setSize(400,300);

this.setLocation(300, 200);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand().equals("open")){

//System.out.println("打开");

JFileChooser fileChoose=new JFileChooser();

fileChoose.setDialogTitle("文件打开");

fileChoose.showOpenDialog(null);

fileChoose.setVisible(true);

String files=fileChoose.getSelectedFile().getAbsolutePath();

//得到用户选择的全路径

FileReader reader=null;

BufferedReader buffer=null;

try{

reader=new FileReader(files);

buffer=new BufferedReader(reader);

String s="",zfc="";

while((s=buffer.readLine())!=null)

{

zfc+=(s+"\n");

}

}catch(Exception aa){

}

finally {

try{

reader.close();

buffer.close();

}catch(Exception ee){

}

}

}else if(e.getActionCommand().equals("save")){

System.out.println("保存");

JFileChooser filechoose=new JFileChooser();

filechoose.setDialogTitle("另存为");

filechoose.showSaveDialog(null);

filechoose.setVisible(true);

String str=filechoose.getSelectedFile().getAbsolutePath();

try{

PrintStream print =new PrintStream(str);

System.setOut(print);

System.out.println(this.textArea.getText());

}catch(Exception aa){

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值