Results 1 to 2 of 2
- 10-17-2012, 11:59 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
Updating text area according to system time thread
I am writing a program to log and display data through a serial port. I can display what ports are available and read information from them. I am going to be using this to read data from Arduino as well as DAQs. I am unable to display the data continuously inside of my jtextarea. I have a clock that displays the system time and every time it increments I want to display the time and the data being received in the text area. This is jtextarea1 in my code. Jtextarea2 is simply for displaying test information. If anyone knows how I could update my textarea this way please let me know. I already have a thread running for my clock. I want the text area to update while the clock is running. I am unable to use t.isAlive() as a parameter in my while loop... not sure why. Here are a couple sections of my code to give you a general idea. This is my first time using netbeans.
This is the action performed for my start button that begins the clock and everything else. I indicated in a comment where my while loop is that is not appending to the text area. Without the while loop I will only get one line of data, but with the loop my program crashes:
Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { getText(); t.start(); String COMPort = jTextField2.getText(); String BaudRate = jTextField3.getText(); jTextArea2.append("Serial Port: " + COMPort +"\n"); jTextArea2.append("Baud Rate: " + BaudRate + "\n"); serialPortOpen(); byte[] buffer; while(serialPort.isOpened() == true){ // problem is here try { buffer = serialPort.readBytes(10); jTextArea1.append(buffer + "\n"); } catch (SerialPortException ex) { jTextArea2.append("Serial Port Error"); } } }
- 10-18-2012, 04:48 AM #2
Re: Updating text area according to system time thread
Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Code Conventions for the Java Programming Language -- variable names should start with a lowercase letter
Not a NetBeans question, moving to AWT/Swing.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Full Time Java Engineers in the Chicago area Apply
By recruitht in forum Jobs OfferedReplies: 0Last Post: 09-18-2012, 06:12 PM -
adding text to a text area dynamically
By tom2zip in forum AWT / SwingReplies: 3Last Post: 01-17-2012, 05:58 AM -
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 02:38 PM -
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM -
How display text in listbox or text area right to left or center??
By sameer22 in forum CLDC and MIDPReplies: 0Last Post: 09-28-2010, 09:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks