Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

JTextArea used as a modem terminal

 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
Would be greatful in seeing your code for displaying the contents of the serial port..
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic