File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTextArea used as a modem terminal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply locked New topic
Author

JTextArea used as a modem terminal

Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I am trying to create a pseudo terminal program, which prints characters from the serial port to a JTextArea. When the user types in the JTextArea, I want the text sent out the serial port.

I can do the first part with no problem. I'm stumped on the second. A normal modem terminal has a setting for local echo. If its on, then each key you type shows up in the window and gets sent out. If its off, then the character is simply sent out the serial port.

How can emulate this behavior? I know I can register a KeyListener, but that won't help if the key already shows up in the text area and its not supposed to.

Any ideas?

Thanks,
Aaron R>
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
Figured it out!

Register a KeyListener with the JTextPanel. In the keyTyped() method of the listener, do a consume on the key event if you don't want it to show up in the textpanel.

Works like a charm.

Regards,
Aaron R>
Fernando Hood
Greenhorn

Joined: May 23, 2008
Posts: 20
Would be greatful in seeing your code for displaying the contents of the serial port..
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by FERNANDO HOOD:
Would be greatful in seeing your code for displaying the contents of the serial port..


Please don't drudge up posts that are nearly 4 years old. I am closing this thread as the OP solved his own problem anyway so there is no need for any more discussion.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextArea used as a modem terminal