主题:textArea.getDocument().addUndoableEditListener疑问
class Test extends JFrame
{ final UndoManager undo =new UndoManager();
UndoableEditListener undoHandler = new UndoHandler();
JTextArea textArea=new JTextArea();
.....
public Test()
{ ....
textArea.getDocument().addUndoableEditListener(undoHandler);
.....
}
class UndoHandler implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent e)
{
undo.addEdit(e.getEdit());
}
}
}
textArea.getDocument().addUndoableEditListener(undoHandler);这句放的位置有没有限制
我把它放到构造函数Test()外 怎么就编译不通过
{ final UndoManager undo =new UndoManager();
UndoableEditListener undoHandler = new UndoHandler();
JTextArea textArea=new JTextArea();
.....
public Test()
{ ....
textArea.getDocument().addUndoableEditListener(undoHandler);
.....
}
class UndoHandler implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent e)
{
undo.addEdit(e.getEdit());
}
}
}
textArea.getDocument().addUndoableEditListener(undoHandler);这句放的位置有没有限制
我把它放到构造函数Test()外 怎么就编译不通过