The benefit of using an Action is that it can be shared by any component that supports Actions.
So instead of trying to implement multiple annonymous inner classes, you should be creating a single Action. Then you can create your JMenuItem with this Action.
Another benefit of using the Action is that you can assign the accelerator and mnemonic keys directly to the Action. Swing will then do the Keystroke bindings for you automatically when you create the menu item.
Read the section from the Swing tutorial on How to Use Actions for more information. There is also a section on Text Component Features that demos working undo/redo Actions.