Java记事本代码撤销 java 记事本

java如何实现记事本中的 撤销 功能写一个栈,把前面的操作压入栈里,撤销的时候一个个出栈就可以了 。。
java 记事本的撤销删除 查找 替换 这4个功能你看看这个行不
public void Cut()
{
String temp = notebookframe.textarea.getSelectedText();//获得鼠标拖动选取Java记事本代码撤销的文本
StringSelection text = new StringSelection(temp);//把待剪切的文本传递给 text 对象
clipboard.setContents(text,null);//将文本放入剪切板中
int start = notebookframe.textarea.getSelectionStart();//获取选中文本的开始位置
int end = notebookframe.textarea.getSelectionEnd();//获取选中文本的结束位置
notebookframe.textarea.replaceRange("",start,end);//选中的区域用""替换
}
public void Copy()
{
String temp = notebookframe.textarea.getSelectedText();//获得鼠标拖动选取的文本
StringSelection text = new StringSelection(temp);//把待剪切的文本传递给 text 对象
clipboard.setContents(text,null);//将文本放入剪切板中
}
public void Stick()
{
Transferable contexts = clipboard.getContents(notebookframe);//获取剪切板中的内容
DataFlavorflavor = DataFlavor.stringFlavor;//剪切板的风格(系统的标准风格)
if(contexts.isDataFlavorSupported(flavor))//判断风格java是否可用
{
try{
String str = (String)contexts.getTransferData(flavor);
int start = notebookframe.textarea.getSelectionStart();//获取选中文本的开始位置
int end = notebookframe.textarea.getSelectionEnd();//获取选中文本的结束位置
notebookframe.textarea.replaceRange(str,start,end);//替换光标所在位置的文本
}
catch(Exception ee){}
}
}
public void Delete()
{
String temp = notebookframe.textarea.getSelectedText();//获得鼠标拖动选取的文本
int start = notebookframe.textarea.getSelectionStart();
int end = notebookframe.textarea.getSelectionEnd();
notebookframe.textarea.replaceRange("",start,end);//选中的区域用""替换
}
public void LookUp()
{
searchfor();
}
public void LookUpNext()
{
if(!notebookframe.textarea.getText().equals(""))
{
search.nextShear();
}
else
{
JOptionPane.showMessageDialog(this,"文本内容不为空时才能使用该功能Java记事本代码撤销!","记事本",JOptionPane.WARNING_MESSAGE);
}
}
java怎么实现记事本中的 撤销 功能// ---------------创建撤消操作管理器
protected UndoManager undo = new UndoManager();
protected UndoableEditListener undoHandler = new UndoHandler();
// 撤消
else if (e.getSource() == mEdit_Undo || e.getSource() == popupMenu_Undo || e.getSource() == undoButton) {
Text.requestFocus();
if (undo.canUndo()) {
try {
undo.undo();
} catch (CannotUndoException ex) {
System.out.println("Unable to undo: "ex);
ex.printStackTrace();
}
if (!undo.canUndo()) {
mEdit_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);
}
}
}
//兄弟连Java战狼班
【Java记事本代码撤销 java 记事本】关于Java记事本代码撤销和java 记事本的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读