Hi,
Originally posted by Marcus Hathaway:
Instead i keep using inner classes inside the class for all event actions. Is this a good/bad way to handle things?
...
i have been writing classes recently that are 100s of lines of code and in some cases, similar classes have also been 100s of lines of code when
...
I mean....do people ever go as far as writing classes that may, for instance, just return a JPanel or something? Or is this going a bit to far?
Some good questions.
1. Inner classes have their place, especially for action listeners on Swing components. I don't think they are bad style. But they can clutter a class file and make it hard to read the flow of the code. For this reason, I like to make them their own class.
For example, I have an action like:
and I use it like this in the main GUI construction class:
Writing my code this way has helped to cut down the size of individual class files. All the code still exists somewhere and has to be written, but doing it this way makes it more managable for me.
2. Yes, I do write methods to return a JPanel with a few components added onto it. Sometimes I make this into its own class. For similar reasons of just breaking up the task of building a GUI into smaller manageable chunks.
I hate having a big long GUI initialization method of hundreds of lines. But I do like having an initialization method that delegates work to (if need be) 10-20 other private helper methods (or even other classes if possible).
Hope this gives you some ideas.
Cheers, Jared.