在 MVC 中实现撤消/重做
我有一个 Java 应用程序,我想实现撤消/重做选项。我想要存储并且希望能够恢复的值是一个整数。
我的类 Model
实现了接口 StateEditable
,我必须重新定义 2 个函数 restoreState(Hashtable state)
和 >storeState(Hashtable
但我不知道该放什么。如果有人能帮助我做到这一点,那就太好了。 这些是我的 Model
类的第一行,我想要对其执行撤消/重做的值是 value
public class Model extends Observable implements StateEditable
{
private int value = 5;
private UndoManager undoRedo = new UndoManager();
final UndoableEditListener editListener = new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent evt) {
undoRedo.addEdit(evt.getEdit());
}
};
@Override
public void restoreState(Hashtable<?, ?> state)
{
}
@Override
public void storeState(Hashtable<Object, Object> state)
{
}
}
I have a Java application and I want to implement an Undo/Redo option. the value that I want to stock and that I want to be able to recover is an integer.
My Class Model
implements the interface StateEditable
and I have to redefine the 2 functions restoreState(Hashtable<?, ?> state)
and storeState(Hashtable<Object, Object> state)
but I don't know what to put on them. It will be really great if somebody can help me to do that.
These are the first lines of my Model
class, the value that I want to do an undo/redo on it is value
public class Model extends Observable implements StateEditable
{
private int value = 5;
private UndoManager undoRedo = new UndoManager();
final UndoableEditListener editListener = new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent evt) {
undoRedo.addEdit(evt.getEdit());
}
};
@Override
public void restoreState(Hashtable<?, ?> state)
{
}
@Override
public void storeState(Hashtable<Object, Object> state)
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过查看
StateEditable
示例,看起来在您的storeState
方法中,您需要填充传入的Hashtable
。同样,您在restoreState
中分配状态code> 来自传入的Hashtable
。您需要为Hashtable
中的值定义一个键。考虑到这一点,我建议您添加到文件的顶部,然后填写两个方法,如下所示:
From looking through an example of
StateEditable
, it would appear that in yourstoreState
method, you need to populate theHashtable
that is passed in. Similarly, you assign state in yourrestoreState
from theHashtable
that is passed in. You will need to define a key for the value in theHashtable
. With that in mind, I suggest that you addto the top of your file, and then fill out the two methods like so: