记事本里的撤销功能怎么做啊 用javaSE
------解决方案--------------------
1.写个java类
2.代码如下:
// ---------------创建撤消操作管理器
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);
}
}
}
3.test测试
------解决方案--------------------
撤销的是对Document的操作。Document的几个实现内置了对Swing Undo/Redo 机制的支持。
- Java code
addUndoableEditListener(UndoableEditListener listener)Registers the given observer to begin receiving notifications when undoable edits are made to the document.