undoablejcheckboxedit.java

来自「《java事件处理指南》一书的代码,好东西」· Java 代码 · 共 45 行

JAVA
45
字号
import javax.swing.*;import javax.swing.undo.*;public class UndoableJCheckBoxEdit extends AbstractUndoableEdit{/*  The UndoableJCheckBoxEdit class defines two variables, an    *//*  UndoableJCheckBox which serves as a reference to the object  *//*  that generated the event and a boolean which represents the  *//*  selected state of the event source.                          */   private boolean selected;   private UndoableJCheckBox jcb;/*  The UndoableJCheckBoxEdit constructor is passed a reference     *//*  to the object that generated the event.  The selected variable  *//*  is set based on the selected state of the event source.         */   public UndoableJCheckBoxEdit(UndoableJCheckBox checkbox)    {      jcb = checkbox;      selected = jcb.isSelected();   }/*  The redo() method is overridden to include a change to the   *//*  selected state of the event source.                          */   public void redo() throws CannotRedoException   {      super.redo();      jcb.setSelected(selected);   }/*  The undo() method is overridden to include a change to the   *//*  selected state of the event source.                          */   public void undo() throws CannotRedoException   {      super.undo();      jcb.setSelected(!selected);   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?