Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
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?
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.
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?
1 Answer
- Mark aka jack573Lv 71 decade agoFavorite Answer
You could try using a DocumentListener
http://java.sun.com/javase/6/docs/api/javax/swing/...
Get the Document from the JTextField with the getDocument() method.
http://java.sun.com/javase/6/docs/api/javax/swing/...
Add the DocumentListener to the Document with the addDocumentListener( ... ) method.
http://java.sun.com/javase/6/docs/api/javax/swing/...
How to Write a Document Listener
http://java.sun.com/docs/books/tutorial/uiswing/ev...
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.