In Java, how do I design a text analyzer program?

I am in the process of making a translator that uses a special code. I have already made several versions of the program, however they are difficult to use. I designed them all in BreezySwing, but they are difficult for the user to use because the program does not allow for the use of the keyboard.

That is what I want to do next. To keep it simple, I want to create a simple test program first. It's job will be to display a window with two JTextField objects. Then the user will type a string into the first text field. As the user is keying data, the program must instantly display the user's input in the second field. It must also be able to backspace if the user presses the backspace key.

How would I go about designing the syntax for this program?

2009-08-04T19:01:57Z

Here is an example of the interface. Imagine two fields enclosing the text after the labels below and everything enclosed inside a window(the lines represent the boundaries of the text fields):

User Input |abcdefg12345|
Displayed |abcdefg12345|

The text in the 'Displayed' field must instantly appear when the user types the text in the 'User Input' field.

2009-08-10T14:54:50Z

I know nothing about AWT (traditional Java GUI), so it would be best to stick to the BreezySwing syntax.

However, I do know some things about the BufferedReader; which may be useful in my case. Is it possible to use it as an instant text analyzer?

Mark aka jack5732009-08-07T14:44:58Z

Favorite Answer

You could try using a DocumentListener
http://java.sun.com/javase/6/docs/api/javax/swing/event/DocumentListener.html

Get the Document from the JTextField with the getDocument() method.
http://java.sun.com/javase/6/docs/api/javax/swing/text/JTextComponent.html#getDocument()

Add the DocumentListener to the Document with the addDocumentListener( ... ) method.
http://java.sun.com/javase/6/docs/api/javax/swing/text/Document.html#addDocumentListener(javax.swing.event.DocumentListener)

How to Write a Document Listener
http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html

Hope that helps in some way.

[Edit]
OK, the things I said were not to do with AWT, but Swing.

It has been a while since I even looked at the Breezy stuff. I don't think they have anything that will help you with this.

Anyhow, if you are using the swing JTextField and not a TextField from Breezy, what I said will work.

BufferedReader will not help you with what you want to do. You want to be able to react to changes in the TextField when they happen. The only way to do this is with the DocumentListener.