after several years of writing java code i am of the firm belief that inner classes(at least named ones) should only be used when the code inside them is highly dependent on the outer class(uses it's variables and/or methods).
here is a case in point. you don't have to read this code just refer to it.
i used some of this code for my latest project. my menu has more items in it so i decided to do like i did last time. i create a separate top-level class called Menus. well, after the usual stuff: import this and that, need a variable called such and such, i found i had a problem with the two custom actions that are inner classes of the main class. after checking them out i decided i could make them top level classes also. i know this was just an example for the tutorial, but PLEASE.
also i hate their use of braces
don't use the tutorials as an example of good style
now comes the fun part. i get to replace 200 or so lines of code in the main class with 2
private Menus menus = new Menus(this);
i am sorry i was so sure of myself earlier. i have a problem. the UndoAction need a reference to the RedoAction and vice versa. i thought this would be a piece of cake. please help me. the UndoAction wants a reference to the RedoAction and vice versa.
this really screws things up. i have tried a lot of things to no avail. for example, in the constructor i just told it to set enabled true instead of false. yeah that works untill i type something then it is disabled again.
this worked fine when it was inner classes, but i need them to be top level classes so both Word andf Menus can have access to them
this undo and redo stuff doesn't impress me much anyway. undo is the same as backspace and redo you can just type the letter again anyway. if someone can't help me with this i will just delete the features
I'll be honest that I didn't read the code, too much of it. But the undo action and redo action shouldn't be tightly coupled in real code. You should probably have two stacks of 'Actions' each action that can be done is put into the Undo stack (normal forward moving actions would empty the Redo stack). The Undo action pops from the Undo stack, does the work, and puts the Action on the Redo stack. The Redo action should pop from the Redo stack, perform the action and put to the Undo stack.
The Undo action and Redo action should take its state from the size of its particular stack (i.e. Undo stack is empty makes Undo action disabled). Each action requires two stacks but knows nothing about other Actions. It just has to be able to respond to the size of the stack.