Results 1 to 2 of 2
  1. #1
    NiNja07 is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default Event based serial data receiving GUI app

    Hello,
    I am currently working on a GUI app, which receives data from a comm serial port and I am using Rxtx API for this. As the data reception is event based I made a separate class from the GUI class and wrote all the methods and event handlers/listeners into it. The problem is I want a text box in GUI class to display the received messages as they are updated and I cant find a solution how to do it. It may be possible to include the event listener in the GUI class but I want a better approach. Any help will be appreciated. Here's my event listener:
    Java Code:
    public void serialEvent(SerialPortEvent arg0) {
                int data;
              
                try
                {
                    int len = 0;
                    while ( ( data = in.read()) > -1 )
                    {
                        if ( data == '\n' ) {
                            break;
                        }
                        buffer[len++] = (byte) data;
                    }
                    System.out.print(new String(buffer,0,len));
                }
                catch ( IOException e )
                {
                    e.printStackTrace();
                    System.exit(-1);
                }             
            }
    Here in place of System.out.print I want it to be displayed on GUI text area.
    Last edited by NiNja07; 06-22-2011 at 09:44 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    in place of System.out.print I want it to be displayed on GUI text area.
    Create and display the text area in your GUI.
    Use a text area method to add the text to its display. See setText() and append() for example

Similar Threads

  1. GIOVYNET Java Serial Comm event listener
    By Edudlc in forum New To Java
    Replies: 5
    Last Post: 05-17-2011, 02:38 PM
  2. Event, Message based communication
    By a1prashant in forum New To Java
    Replies: 3
    Last Post: 01-08-2011, 06:43 PM
  3. get data from serial port
    By kishkar20003 in forum New To Java
    Replies: 2
    Last Post: 12-27-2010, 11:33 AM
  4. Replies: 7
    Last Post: 06-22-2010, 10:49 AM
  5. java based implementation on serial communication
    By xll in forum Threads and Synchronization
    Replies: 1
    Last Post: 12-08-2009, 07:45 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •