undoablejcheckbox.java

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

JAVA
51
字号
import javax.swing.*;import java.awt.event.*;import javax.swing.event.*;import javax.swing.undo.*;public class UndoableJCheckBox extends JCheckBox{/*  The UndoableJCheckBox class uses an UndoableEditSupport object  *//*  to provide an undoable capability to a JCheckBox.               */   private UndoableEditSupport undoSupport;/*  The constructor calls the JCheckBox constructor and then       *//*  initializes the UndoableEditSupport object.  The event source  *//*  is set to be the UndoableJCheckBox object.                     */   public UndoableJCheckBox(String title)    {      super(title);      undoSupport = new UndoableEditSupport(this);   }/*  The UndoableEditSupport object is used to implement the methods       *//*  to add or remove an UndoableEditListener from the UndoableJCheckBox.  */   public void addUndoableEditListener(UndoableEditListener listener)   {      undoSupport.addUndoableEditListener(listener);   }   public void removeUndoableEditListener(UndoableEditListener listener)   {      undoSupport.removeUndoableEditListener(listener);   }/*  The fireActionPerformed() method is overridden so that when the mouse  *//*  is pressed over the UndoableJCheckBox, an UndoableJCheckBoxEdit object *//*  is created and sent to any registered UndoableEditListeners.           */   protected void fireActionPerformed(ActionEvent event)   {      super.fireActionPerformed(event);      undoSupport.postEdit(new UndoableJCheckBoxEdit(this));   }}

⌨️ 快捷键说明

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