我正在尝试设置UndoManager
一个类似绘画的程序,但不幸地失败了。我一直在看的示例程序是文本编辑器(Example),它们调用addUndoableEditListener
class的方法JTextComponent
。
我应该如何设置 UndoManager 以使用画布?
public class Pisi extends JFrame implements MouseMotionListener, MouseListener,
UndoableEditListener {
ArrayList<ArrayList<Point>> store = new ArrayList<ArrayList<Point>>();
ArrayList<Point> pts = new ArrayList<Point>();
ArrayList<Point> newRed;
ArrayList<Point> currentRed = new ArrayList<Point>();
JPanel panel;
Point start;
static int xsize = 500;
static int ysize = 350;
int listNumber = 0;
int lastPointed = -1;
int pointed = -1;
int clicked = -1;
UndoManager undoManager = new UndoManager();
UndoAction undoAction = new UndoAction();
RedoAction redoAction = new RedoAction();
protected MyUndoableEditListener l = new MyUndoableEditListener();
public Pisi() {
panel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
}
};
setSize(xsize, ysize);
setResizable(false);
getContentPane().setLayout(null);
getContentPane().add(panel);
setLocationRelativeTo(null);
setVisible(true);
panel.setLocation(0, -11);
this.addMouseMotionListener(this);
this.addMouseListener(this);
**this.addUndoableEditListener(this);**
}
public static void main(String[] args) {
Pisi d = new Pisi();
}
*... more code...*
}
所有输入将不胜感激。