当前位置: 代码迷 >> J2SE >> SE里 作记事本的撤销功能
  详细解决方案

SE里 作记事本的撤销功能

热度:31   发布时间:2016-04-24 00:41:09.0
SE里 做记事本的撤销功能
记事本里的撤销功能怎么做啊 用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.
  相关解决方案