undo textarea?

how to add a undo feature to a textarea just like the notepad or microsoft word undo?
[92 byte] By [w32sysfiea] at [2007-11-27 3:28:15]
# 1
start by searching the forum
Michael_Dunna at 2007-7-12 8:31:04 > top of Java-index,Desktop,Core GUI APIs...
# 2

I found this one

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import javax.swing.undo.*;

public class undo {

static UndoManager undomanager;

static class UndoHandler implements UndoableEditListener {

public void undoableEditHappened(UndoableEditEvent e) {

if (undomanager != null) {

undomanager.addEdit(e.getEdit());

//System.out.println(e.getEdit());

}

}

}

public static void main(String args[]) {

// set up frames, panels, text areas

JFrame frame = new JFrame("Undo demo");

frame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

JPanel panel = new JPanel();

panel.setLayout(new BorderLayout());

final JTextArea textarea = new JTextArea(10, 40);

JPanel textpanel = new JPanel();

textpanel.add(new JScrollPane(textarea));

textarea.getDocument().addUndoableEditListener(

new UndoHandler());

// create buttons and set up listeners for them

JPanel buttonpanel = new JPanel();

JButton startbutton = new JButton("Start Edits");

JButton undobutton = new JButton("Undo Edits");

startbutton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

undomanager = new UndoManager();

undomanager.setLimit(1000);

textarea.requestFocus();

}

});

undobutton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (undomanager != null) {

undomanager.end();

undomanager.undo();

undomanager = null;

}

else {

Toolkit.getDefaultToolkit().beep();

}

textarea.requestFocus();

}

});

buttonpanel.add(startbutton);

buttonpanel.add(undobutton);

panel.add("North", textpanel);

panel.add("South", buttonpanel);

// make frame visible

frame.getContentPane().add("Center", panel);

frame.pack();

frame.setVisible(true);

}

}

but many syntax in there that i dont understand

can any1 give me a link to a tutorial about this?

w32sysfiea at 2007-7-12 8:31:04 > top of Java-index,Desktop,Core GUI APIs...
# 3
[url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#undo]Text Component Features[/url]
camickra at 2007-7-12 8:31:04 > top of Java-index,Desktop,Core GUI APIs...