java 删除文件某一行_java文本操作 删除文本中的某一行(或一个对象)

展开全部

你说的不就是一个记事本吗,

//import java packages

import java.awt.*;

import java.awt.event.*;

import java.text.*;

import java.util.*;

import java.io.*;

import javax.swing.undo.*;

import javax.swing.border.*;

import javax.swing.*;

import javax.swing.text.*;

import javax.swing.event.*;

import java.awt.datatransfer.*;

public class Notepad extends JFrame implements ActionListener,DocumentListener{

//定义变量

//菜单

JMenu fileMenu,editMenu,formatMenu,viewMenu,helpMenu;

//"文件"的菜单项62616964757a686964616fe4b893e5b19e31333236396536

JMenuItem fileMenu_New,fileMenu_Open,fileMenu_Save,fileMenu_SaveAs,fileMenu_PageSetup,fileMenu_Print,fileMenu_Exit;

//"编辑"的菜单项

JMenuItem editMenu_Undo,editMenu_Redo,editMenu_Cut,editMenu_Copy,editMenu_Paste,editMenu_Delete,editMenu_Find,editMenu_FindNext,editMenu_Replace,

editMenu_GoTo,editMenu_SelectAll,editMenu_TimeDate;

//"格式"的菜单项

JCheckBoxMenuItem formatMenu_LineWrap;

JMenu formatMenu_Color;

JMenuItem formatMenu_Font,formatMenu_Color_FgColor,formatMenu_Color_BgColor;

//"查看"的菜单项

JCheckBoxMenuItem viewMenu_Status;

//"帮助"的菜单项

JMenuItem helpMenu_HelpTopics,helpMenu_About;

//文本编辑区域

JTextArea editArea;

//状态栏标签

JLabel statusLabel;

//弹出菜单及菜单项

JPopupMenu popupMenu;

JMenuItem popupMenu_Undo,popupMenu_Redo,popupMenu_Cut,popupMenu_Copy,popupMenu_Paste,popupMenu_Delete,popupMenu_SelectAll;

//系统剪贴板

Toolkit toolKit=Toolkit.getDefaultToolkit();

Clipboard clipBoard=toolKit.getSystemClipboard();

//其它变量

boolean isNewFile=true; //是否新文件(未保存过的)

File currentFile; //当前文件名

String oldValue; //存放编辑区原来的内容,用于比较文本是否有改动

JButton fontOkButton; //字体设置里的"确定"按钮

//工具栏按钮

JButton newButton,openButton,saveButton,saveAsButton,printButton,undoButton,redoButton,

cutButton,copyButton,pasteButton,deleteButton,searchButton,timeButton,fontButton,

boldButton,italicButton,fgcolorButton,bgcolorButton,helpButton;

//创建撤消操作管理器

protected UndoManager undo = new UndoManager();

protected UndoableEditListener undoHandler = new UndoHandler();

//设置编辑区默认字体

protected Font defaultFont=new Font("宋体",Font.PLAIN,12);

//构造函数开始

public Notepad()

{

super("黄斌的记事本");

//获取容器

Container container=getContentPane();

//创建菜单条

JMenuBar menuBar = new JMenuBar();

//创建文件菜单及菜单项并注册事件监听

JMenu fileMenu = new JMenu("文件(F)", true);

fileMenu.setMnemonic('F');

fileMenu_New = new JMenuItem("新建(N)", 'N');

fileMenu_New.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));

fileMenu_New.addActionListener(this);

fileMenu_Open = new JMenuItem("打开(O)...", 'O');

fileMenu_Open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));

fileMenu_Open.addActionListener(this);

fileMenu_Save = new JMenuItem("保存(S)", 'S');

fileMenu_Save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));

fileMenu_Save.addActionListener(this);

fileMenu_SaveAs = new JMenuItem("

你可能感兴趣的:(java,删除文件某一行)