Note that there are some explanatory texts on larger screens.

plurals
  1. POJava 6: How to set up UndoManager to work with a canvas?
    primarykey
    data
    text
    <p>I am trying to set up <code>UndoManager</code> in a paint-like program, but miserably failing at that. The sample programs, which I have been looking at, are text editors (<a href="http://www.example8.com/node/view/id/18933" rel="nofollow">Example</a>) and they call the method <code>addUndoableEditListener</code> of class <code>JTextComponent</code>. </p> <p>How should I set up UndoManager to work with a canvas? </p> <pre class="lang-java prettyprint-override"><code>public class Pisi extends JFrame implements MouseMotionListener, MouseListener, UndoableEditListener { ArrayList&lt;ArrayList&lt;Point&gt;&gt; store = new ArrayList&lt;ArrayList&lt;Point&gt;&gt;(); ArrayList&lt;Point&gt; pts = new ArrayList&lt;Point&gt;(); ArrayList&lt;Point&gt; newRed; ArrayList&lt;Point&gt; currentRed = new ArrayList&lt;Point&gt;(); JPanel panel; Point start; static int xsize = 500; static int ysize = 350; int listNumber = 0; int lastPointed = -1; int pointed = -1; int clicked = -1; UndoManager undoManager = new UndoManager(); UndoAction undoAction = new UndoAction(); RedoAction redoAction = new RedoAction(); protected MyUndoableEditListener l = new MyUndoableEditListener(); public Pisi() { panel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); } }; setSize(xsize, ysize); setResizable(false); getContentPane().setLayout(null); getContentPane().add(panel); setLocationRelativeTo(null); setVisible(true); panel.setLocation(0, -11); this.addMouseMotionListener(this); this.addMouseListener(this); **this.addUndoableEditListener(this);** } public static void main(String[] args) { Pisi d = new Pisi(); } *... more code...* } </code></pre> <p>All input will be well appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload