<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjavax.swing.undo%2FStateEdit</id>
		<title>Java by API/javax.swing.undo/StateEdit - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjavax.swing.undo%2FStateEdit"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/javax.swing.undo/StateEdit&amp;action=history"/>
		<updated>2026-04-27T15:57:35Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/javax.swing.undo/StateEdit&amp;diff=1897&amp;oldid=prev</id>
		<title> в 17:43, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/javax.swing.undo/StateEdit&amp;diff=1897&amp;oldid=prev"/>
				<updated>2010-05-31T17:43:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:43, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/javax.swing.undo/StateEdit&amp;diff=1898&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/javax.swing.undo/StateEdit&amp;diff=1898&amp;oldid=prev"/>
				<updated>2010-05-31T14:38:20Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== StateEdit: canRedo() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.Container;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
import javax.swing.Box;&lt;br /&gt;
import javax.swing.BoxLayout;&lt;br /&gt;
import javax.swing.JButton;&lt;br /&gt;
import javax.swing.JCheckBox;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JRadioButton;&lt;br /&gt;
import javax.swing.JToggleButton;&lt;br /&gt;
import javax.swing.undo.CannotRedoException;&lt;br /&gt;
import javax.swing.undo.CannotUndoException;&lt;br /&gt;
import javax.swing.undo.StateEdit;&lt;br /&gt;
import javax.swing.undo.StateEditable;&lt;br /&gt;
public class UndoableToggleApp4 extends JFrame implements StateEditable {&lt;br /&gt;
  private JToggleButton tog = new JToggleButton(&amp;quot;ToggleButton&amp;quot;);&lt;br /&gt;
  private JCheckBox cb = new JCheckBox(&amp;quot;CheckBox&amp;quot;);&lt;br /&gt;
  private JRadioButton radio = new JRadioButton(&amp;quot;RadioButton&amp;quot;);&lt;br /&gt;
  private JButton  undoButton = new JButton(&amp;quot;Undo&amp;quot;);&lt;br /&gt;
  private JButton   redoButton = new JButton(&amp;quot;Redo&amp;quot;);&lt;br /&gt;
  private JButton startButton = new JButton(&amp;quot;Start&amp;quot;);&lt;br /&gt;
  private JButton endButton = new JButton(&amp;quot;End&amp;quot;);&lt;br /&gt;
  private StateEdit edit;&lt;br /&gt;
  public UndoableToggleApp4() {&lt;br /&gt;
    SimpleListener sl = new SimpleListener();&lt;br /&gt;
    tog.addActionListener(sl);&lt;br /&gt;
    cb.addActionListener(sl);&lt;br /&gt;
    radio.addActionListener(sl);&lt;br /&gt;
    Box buttonBox = new Box(BoxLayout.Y_AXIS);&lt;br /&gt;
    buttonBox.add(tog);&lt;br /&gt;
    buttonBox.add(cb);&lt;br /&gt;
    buttonBox.add(radio);&lt;br /&gt;
    startButton.setEnabled(true);&lt;br /&gt;
    endButton.setEnabled(false);&lt;br /&gt;
    undoButton.setEnabled(false);&lt;br /&gt;
    redoButton.setEnabled(false);&lt;br /&gt;
    startButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        edit = new StateEdit(UndoableToggleApp4.this);&lt;br /&gt;
        startButton.setEnabled(false);&lt;br /&gt;
        endButton.setEnabled(true);&lt;br /&gt;
        // undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
        //&lt;br /&gt;
        // NOTE: We really don&amp;quot;t want to be able to undo until end() is pressed,&lt;br /&gt;
        // but StateEdit does not enforce this for us!&lt;br /&gt;
        undoButton.setEnabled(false);&lt;br /&gt;
        redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    endButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        edit.end();&lt;br /&gt;
        startButton.setEnabled(true);&lt;br /&gt;
        endButton.setEnabled(false);&lt;br /&gt;
        undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
        redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Add a listener to the undo button. It attempts to call undo() on the&lt;br /&gt;
    // current edit, then enables/disables the undo/redo buttons as appropriate.&lt;br /&gt;
    undoButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        try {&lt;br /&gt;
          edit.undo();&lt;br /&gt;
        } catch (CannotUndoException ex) {&lt;br /&gt;
          ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
          undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
          redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    redoButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        try {&lt;br /&gt;
          edit.redo();&lt;br /&gt;
        } catch (CannotRedoException ex) {&lt;br /&gt;
          ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
          undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
          redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Lay out the state/end and undo/redo buttons.&lt;br /&gt;
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);&lt;br /&gt;
    undoRedoBox.add(Box.createGlue());&lt;br /&gt;
    undoRedoBox.add(startButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(endButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(undoButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(redoButton);&lt;br /&gt;
    undoRedoBox.add(Box.createGlue());&lt;br /&gt;
    // Lay out the main frame.&lt;br /&gt;
    Container content = getContentPane();&lt;br /&gt;
    content.setLayout(new BorderLayout());&lt;br /&gt;
    content.add(buttonBox, BorderLayout.CENTER);&lt;br /&gt;
    content.add(undoRedoBox, BorderLayout.SOUTH);&lt;br /&gt;
    setSize(400, 150);&lt;br /&gt;
  }&lt;br /&gt;
  public class SimpleListener implements ActionListener {&lt;br /&gt;
    // When any toggle button is clicked, we turn off the undo and redo&lt;br /&gt;
    // buttons, reflecting the fact that we can only undo/redo the last&lt;br /&gt;
    // set of state changes as long as no additional changes have been made.&lt;br /&gt;
    public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
      undoButton.setEnabled(false);&lt;br /&gt;
      redoButton.setEnabled(false);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // Save the state of the app by storing the current state of the three&lt;br /&gt;
  // buttons. We&amp;quot;ll use the buttons themselves as keys and their selected&lt;br /&gt;
  // state as values.&lt;br /&gt;
  public void storeState(Hashtable ht) {&lt;br /&gt;
    ht.put(tog, new Boolean(tog.isSelected()));&lt;br /&gt;
    ht.put(cb, new Boolean(cb.isSelected()));&lt;br /&gt;
    ht.put(radio, new Boolean(radio.isSelected()));&lt;br /&gt;
  }&lt;br /&gt;
  // Restore state based on the values we saved when storeState() was called.&lt;br /&gt;
  // Note that StateEdit discards any state info that did not change from&lt;br /&gt;
  // between the start state and the end state, so we can&amp;quot;t assume that the&lt;br /&gt;
  // state for all 3 buttons is in the Hashtable.&lt;br /&gt;
  public void restoreState(Hashtable ht) {&lt;br /&gt;
    Boolean b1 = (Boolean) ht.get(tog);&lt;br /&gt;
    if (b1 != null)&lt;br /&gt;
      tog.setSelected(b1.booleanValue());&lt;br /&gt;
    Boolean b2 = (Boolean) ht.get(cb);&lt;br /&gt;
    if (b2 != null)&lt;br /&gt;
      cb.setSelected(b2.booleanValue());&lt;br /&gt;
    Boolean b3 = (Boolean) ht.get(radio);&lt;br /&gt;
    if (b3 != null)&lt;br /&gt;
      radio.setSelected(b3.booleanValue());&lt;br /&gt;
  }&lt;br /&gt;
  // Main program just creates the frame and displays it.&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    JFrame f = new UndoableToggleApp4();&lt;br /&gt;
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    f.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== StateEdit: canUndo() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.Container;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
import javax.swing.Box;&lt;br /&gt;
import javax.swing.BoxLayout;&lt;br /&gt;
import javax.swing.JButton;&lt;br /&gt;
import javax.swing.JCheckBox;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JRadioButton;&lt;br /&gt;
import javax.swing.JToggleButton;&lt;br /&gt;
import javax.swing.undo.CannotRedoException;&lt;br /&gt;
import javax.swing.undo.CannotUndoException;&lt;br /&gt;
import javax.swing.undo.StateEdit;&lt;br /&gt;
import javax.swing.undo.StateEditable;&lt;br /&gt;
public class UndoableToggleApp4 extends JFrame implements StateEditable {&lt;br /&gt;
  private JToggleButton tog = new JToggleButton(&amp;quot;ToggleButton&amp;quot;);&lt;br /&gt;
  private JCheckBox cb = new JCheckBox(&amp;quot;CheckBox&amp;quot;);&lt;br /&gt;
  private JRadioButton radio = new JRadioButton(&amp;quot;RadioButton&amp;quot;);&lt;br /&gt;
  private JButton  undoButton = new JButton(&amp;quot;Undo&amp;quot;);&lt;br /&gt;
  private JButton   redoButton = new JButton(&amp;quot;Redo&amp;quot;);&lt;br /&gt;
  private JButton startButton = new JButton(&amp;quot;Start&amp;quot;);&lt;br /&gt;
  private JButton endButton = new JButton(&amp;quot;End&amp;quot;);&lt;br /&gt;
  private StateEdit edit;&lt;br /&gt;
  public UndoableToggleApp4() {&lt;br /&gt;
    SimpleListener sl = new SimpleListener();&lt;br /&gt;
    tog.addActionListener(sl);&lt;br /&gt;
    cb.addActionListener(sl);&lt;br /&gt;
    radio.addActionListener(sl);&lt;br /&gt;
    Box buttonBox = new Box(BoxLayout.Y_AXIS);&lt;br /&gt;
    buttonBox.add(tog);&lt;br /&gt;
    buttonBox.add(cb);&lt;br /&gt;
    buttonBox.add(radio);&lt;br /&gt;
    startButton.setEnabled(true);&lt;br /&gt;
    endButton.setEnabled(false);&lt;br /&gt;
    undoButton.setEnabled(false);&lt;br /&gt;
    redoButton.setEnabled(false);&lt;br /&gt;
    startButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        edit = new StateEdit(UndoableToggleApp4.this);&lt;br /&gt;
        startButton.setEnabled(false);&lt;br /&gt;
        endButton.setEnabled(true);&lt;br /&gt;
        // undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
        //&lt;br /&gt;
        // NOTE: We really don&amp;quot;t want to be able to undo until end() is pressed,&lt;br /&gt;
        // but StateEdit does not enforce this for us!&lt;br /&gt;
        undoButton.setEnabled(false);&lt;br /&gt;
        redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    endButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        edit.end();&lt;br /&gt;
        startButton.setEnabled(true);&lt;br /&gt;
        endButton.setEnabled(false);&lt;br /&gt;
        undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
        redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Add a listener to the undo button. It attempts to call undo() on the&lt;br /&gt;
    // current edit, then enables/disables the undo/redo buttons as appropriate.&lt;br /&gt;
    undoButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        try {&lt;br /&gt;
          edit.undo();&lt;br /&gt;
        } catch (CannotUndoException ex) {&lt;br /&gt;
          ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
          undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
          redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    redoButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        try {&lt;br /&gt;
          edit.redo();&lt;br /&gt;
        } catch (CannotRedoException ex) {&lt;br /&gt;
          ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
          undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
          redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Lay out the state/end and undo/redo buttons.&lt;br /&gt;
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);&lt;br /&gt;
    undoRedoBox.add(Box.createGlue());&lt;br /&gt;
    undoRedoBox.add(startButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(endButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(undoButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(redoButton);&lt;br /&gt;
    undoRedoBox.add(Box.createGlue());&lt;br /&gt;
    // Lay out the main frame.&lt;br /&gt;
    Container content = getContentPane();&lt;br /&gt;
    content.setLayout(new BorderLayout());&lt;br /&gt;
    content.add(buttonBox, BorderLayout.CENTER);&lt;br /&gt;
    content.add(undoRedoBox, BorderLayout.SOUTH);&lt;br /&gt;
    setSize(400, 150);&lt;br /&gt;
  }&lt;br /&gt;
  public class SimpleListener implements ActionListener {&lt;br /&gt;
    // When any toggle button is clicked, we turn off the undo and redo&lt;br /&gt;
    // buttons, reflecting the fact that we can only undo/redo the last&lt;br /&gt;
    // set of state changes as long as no additional changes have been made.&lt;br /&gt;
    public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
      undoButton.setEnabled(false);&lt;br /&gt;
      redoButton.setEnabled(false);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // Save the state of the app by storing the current state of the three&lt;br /&gt;
  // buttons. We&amp;quot;ll use the buttons themselves as keys and their selected&lt;br /&gt;
  // state as values.&lt;br /&gt;
  public void storeState(Hashtable ht) {&lt;br /&gt;
    ht.put(tog, new Boolean(tog.isSelected()));&lt;br /&gt;
    ht.put(cb, new Boolean(cb.isSelected()));&lt;br /&gt;
    ht.put(radio, new Boolean(radio.isSelected()));&lt;br /&gt;
  }&lt;br /&gt;
  // Restore state based on the values we saved when storeState() was called.&lt;br /&gt;
  // Note that StateEdit discards any state info that did not change from&lt;br /&gt;
  // between the start state and the end state, so we can&amp;quot;t assume that the&lt;br /&gt;
  // state for all 3 buttons is in the Hashtable.&lt;br /&gt;
  public void restoreState(Hashtable ht) {&lt;br /&gt;
    Boolean b1 = (Boolean) ht.get(tog);&lt;br /&gt;
    if (b1 != null)&lt;br /&gt;
      tog.setSelected(b1.booleanValue());&lt;br /&gt;
    Boolean b2 = (Boolean) ht.get(cb);&lt;br /&gt;
    if (b2 != null)&lt;br /&gt;
      cb.setSelected(b2.booleanValue());&lt;br /&gt;
    Boolean b3 = (Boolean) ht.get(radio);&lt;br /&gt;
    if (b3 != null)&lt;br /&gt;
      radio.setSelected(b3.booleanValue());&lt;br /&gt;
  }&lt;br /&gt;
  // Main program just creates the frame and displays it.&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    JFrame f = new UndoableToggleApp4();&lt;br /&gt;
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    f.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== StateEdit: end() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.Container;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
import javax.swing.Box;&lt;br /&gt;
import javax.swing.BoxLayout;&lt;br /&gt;
import javax.swing.JButton;&lt;br /&gt;
import javax.swing.JCheckBox;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JRadioButton;&lt;br /&gt;
import javax.swing.JToggleButton;&lt;br /&gt;
import javax.swing.undo.CannotRedoException;&lt;br /&gt;
import javax.swing.undo.CannotUndoException;&lt;br /&gt;
import javax.swing.undo.StateEdit;&lt;br /&gt;
import javax.swing.undo.StateEditable;&lt;br /&gt;
public class UndoableToggleApp4 extends JFrame implements StateEditable {&lt;br /&gt;
  private JToggleButton tog = new JToggleButton(&amp;quot;ToggleButton&amp;quot;);&lt;br /&gt;
  private JCheckBox cb = new JCheckBox(&amp;quot;CheckBox&amp;quot;);&lt;br /&gt;
  private JRadioButton radio = new JRadioButton(&amp;quot;RadioButton&amp;quot;);&lt;br /&gt;
  private JButton  undoButton = new JButton(&amp;quot;Undo&amp;quot;);&lt;br /&gt;
  private JButton   redoButton = new JButton(&amp;quot;Redo&amp;quot;);&lt;br /&gt;
  private JButton startButton = new JButton(&amp;quot;Start&amp;quot;);&lt;br /&gt;
  private JButton endButton = new JButton(&amp;quot;End&amp;quot;);&lt;br /&gt;
  private StateEdit edit;&lt;br /&gt;
  public UndoableToggleApp4() {&lt;br /&gt;
    SimpleListener sl = new SimpleListener();&lt;br /&gt;
    tog.addActionListener(sl);&lt;br /&gt;
    cb.addActionListener(sl);&lt;br /&gt;
    radio.addActionListener(sl);&lt;br /&gt;
    Box buttonBox = new Box(BoxLayout.Y_AXIS);&lt;br /&gt;
    buttonBox.add(tog);&lt;br /&gt;
    buttonBox.add(cb);&lt;br /&gt;
    buttonBox.add(radio);&lt;br /&gt;
    startButton.setEnabled(true);&lt;br /&gt;
    endButton.setEnabled(false);&lt;br /&gt;
    undoButton.setEnabled(false);&lt;br /&gt;
    redoButton.setEnabled(false);&lt;br /&gt;
    startButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        edit = new StateEdit(UndoableToggleApp4.this);&lt;br /&gt;
        startButton.setEnabled(false);&lt;br /&gt;
        endButton.setEnabled(true);&lt;br /&gt;
        // undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
        //&lt;br /&gt;
        // NOTE: We really don&amp;quot;t want to be able to undo until end() is pressed,&lt;br /&gt;
        // but StateEdit does not enforce this for us!&lt;br /&gt;
        undoButton.setEnabled(false);&lt;br /&gt;
        redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    endButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        edit.end();&lt;br /&gt;
        startButton.setEnabled(true);&lt;br /&gt;
        endButton.setEnabled(false);&lt;br /&gt;
        undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
        redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Add a listener to the undo button. It attempts to call undo() on the&lt;br /&gt;
    // current edit, then enables/disables the undo/redo buttons as appropriate.&lt;br /&gt;
    undoButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        try {&lt;br /&gt;
          edit.undo();&lt;br /&gt;
        } catch (CannotUndoException ex) {&lt;br /&gt;
          ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
          undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
          redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    redoButton.addActionListener(new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
        try {&lt;br /&gt;
          edit.redo();&lt;br /&gt;
        } catch (CannotRedoException ex) {&lt;br /&gt;
          ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
          undoButton.setEnabled(edit.canUndo());&lt;br /&gt;
          redoButton.setEnabled(edit.canRedo());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Lay out the state/end and undo/redo buttons.&lt;br /&gt;
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);&lt;br /&gt;
    undoRedoBox.add(Box.createGlue());&lt;br /&gt;
    undoRedoBox.add(startButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(endButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(undoButton);&lt;br /&gt;
    undoRedoBox.add(Box.createHorizontalStrut(2));&lt;br /&gt;
    undoRedoBox.add(redoButton);&lt;br /&gt;
    undoRedoBox.add(Box.createGlue());&lt;br /&gt;
    // Lay out the main frame.&lt;br /&gt;
    Container content = getContentPane();&lt;br /&gt;
    content.setLayout(new BorderLayout());&lt;br /&gt;
    content.add(buttonBox, BorderLayout.CENTER);&lt;br /&gt;
    content.add(undoRedoBox, BorderLayout.SOUTH);&lt;br /&gt;
    setSize(400, 150);&lt;br /&gt;
  }&lt;br /&gt;
  public class SimpleListener implements ActionListener {&lt;br /&gt;
    // When any toggle button is clicked, we turn off the undo and redo&lt;br /&gt;
    // buttons, reflecting the fact that we can only undo/redo the last&lt;br /&gt;
    // set of state changes as long as no additional changes have been made.&lt;br /&gt;
    public void actionPerformed(ActionEvent ev) {&lt;br /&gt;
      undoButton.setEnabled(false);&lt;br /&gt;
      redoButton.setEnabled(false);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // Save the state of the app by storing the current state of the three&lt;br /&gt;
  // buttons. We&amp;quot;ll use the buttons themselves as keys and their selected&lt;br /&gt;
  // state as values.&lt;br /&gt;
  public void storeState(Hashtable ht) {&lt;br /&gt;
    ht.put(tog, new Boolean(tog.isSelected()));&lt;br /&gt;
    ht.put(cb, new Boolean(cb.isSelected()));&lt;br /&gt;
    ht.put(radio, new Boolean(radio.isSelected()));&lt;br /&gt;
  }&lt;br /&gt;
  // Restore state based on the values we saved when storeState() was called.&lt;br /&gt;
  // Note that StateEdit discards any state info that did not change from&lt;br /&gt;
  // between the start state and the end state, so we can&amp;quot;t assume that the&lt;br /&gt;
  // state for all 3 buttons is in the Hashtable.&lt;br /&gt;
  public void restoreState(Hashtable ht) {&lt;br /&gt;
    Boolean b1 = (Boolean) ht.get(tog);&lt;br /&gt;
    if (b1 != null)&lt;br /&gt;
      tog.setSelected(b1.booleanValue());&lt;br /&gt;
    Boolean b2 = (Boolean) ht.get(cb);&lt;br /&gt;
    if (b2 != null)&lt;br /&gt;
      cb.setSelected(b2.booleanValue());&lt;br /&gt;
    Boolean b3 = (Boolean) ht.get(radio);&lt;br /&gt;
    if (b3 != null)&lt;br /&gt;
      radio.setSelected(b3.booleanValue());&lt;br /&gt;
  }&lt;br /&gt;
  // Main program just creates the frame and displays it.&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    JFrame f = new UndoableToggleApp4();&lt;br /&gt;
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    f.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>