Maneesh Godbole wrote:In future, while posting code, please UseCodeTags . . .
. . . and also go through some
style guidelines. I don't agree with everything there, nor in the Sun style guide referenced there, but things like consistent indentation and use of whitespace would make your code much easier to read.
So many people are taught to use \n, but
here you find you ought to use %n rather than \n.
You should use printf rather than println to get %n to work.
So many people are taught to use addActionListener(this), but that is by no means object-oriented programming. You should create classes which implement the ActionListener interface, rather than have a display Component implement that interface. Even though many books, and the
Java tutorials use that comstruct, I believe you should never use it.
It is worth checking what sort of Listener can be added to a text component. You can find Bruce Eckel's
Thinking in Java which has an example program in which displays all the addXXXListener methods a particular class has. Or you can go to the
API documentation and count them by hand. there may be scores of them. Remember to look in the blocks headed "methods inherited from XYZ". You will find an ActionListener is likely to be fired whenever you use the enter key inside your text field. You can find other Listeners which are fired whenever you alter add or remove text from it. Consider which is most appropriate to your requirements.