怎么写重做和撤消的代码? javax.swing.undo包下面有这方面的类,你看一下。《java2图形设计卷IISWING》P895有例子。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 从我的一个程序中节选过来,你应该看得懂protected UndoManager undo = new UndoManager();protected ActionListener undoRedo = new DocumentUndoRedoManager();textArea.getDocument().addUndoableEditListener((UndoableEditListener));toolBar.undoButton.addActionListener(undoRedo);toolBar.undoButton.setActionCommand(UNDO_COMMAND);........//an inner class class DocumentUndoRedoManager implements UndoableEditListener, ActionListener{ public void undoableEditHappened(UndoableEditEvent e){ undo.addEdit(e.getEdit()); check(); } public void actionPerformed(ActionEvent e){ String cmd = e.getActionCommand(); if(cmd.equals(UNDO_COMMAND)){ undo.undo(); }else if(cmd.equals(REDO_COMMAND)){ undo.redo(); } check(); textArea.requestFocus(); } public void check(){ boolean canUndo=undo.canUndo(), canRedo=undo.canRedo(); menuBar.undoMenuItem.setEnabled(canUndo); menuBar.redoMenuItem.setEnabled(canRedo); toolBar.undoButton.setEnabled(canUndo); toolBar.redoButton.setEnabled(canRedo); } } 初学list,求教!!! Path2D和线程控制问题 notifyall必须要放在synchronized里面吗 如何根据对象的属性进行分组 关于jwsdp 2.0中xjc catalog.xsd怎么不生成generated\impl\ 和 generated\impl\runtime\下的东西啊啊? 再一次请教高手HELP~~ 对于JAVA 初学者应该注意什么? Arrays.toString用法和对象数组问题 多谢 anubis 请接分 怎样使jar-- 小问题,安扭事件,在线急!!帮下忙!! 如何延时3秒?
protected ActionListener undoRedo = new DocumentUndoRedoManager();textArea.getDocument().addUndoableEditListener((UndoableEditListener));
toolBar.undoButton.addActionListener(undoRedo);
toolBar.undoButton.setActionCommand(UNDO_COMMAND);
........//an inner class
class DocumentUndoRedoManager implements UndoableEditListener, ActionListener{
public void undoableEditHappened(UndoableEditEvent e){
undo.addEdit(e.getEdit());
check();
}
public void actionPerformed(ActionEvent e){
String cmd = e.getActionCommand();
if(cmd.equals(UNDO_COMMAND)){
undo.undo();
}else if(cmd.equals(REDO_COMMAND)){
undo.redo();
}
check();
textArea.requestFocus();
}
public void check(){
boolean canUndo=undo.canUndo(), canRedo=undo.canRedo();
menuBar.undoMenuItem.setEnabled(canUndo);
menuBar.redoMenuItem.setEnabled(canRedo);
toolBar.undoButton.setEnabled(canUndo);
toolBar.redoButton.setEnabled(canRedo);
}
}