I used SwingWorker with this code but It doesn't work too .I don't know how to display data in jTextArea1. :-[
public synchronized void serialEvent(SerialPortEvent oEvent) {
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
new SwingWorker<Void, String>()
{
@Override
protected Void doInBackground() throws Exception
{
/**if command available hardware respone data here**/
BufferedReader reader = new BufferedReader(new InputStreamReader(input, "tis-620"));
String line = "";
while ((line = reader.readLine()) != null) {
if (line.length() > 0) {
publish(line);
}
}
return null;
}
@Override
protected void process(List<String> chunks)
{
for (String string : chunks)
{
TS.displaySerialData(string);
}
}
@Override
protected void done()
{
// source.setEnabled(true);
}
}.execute();
}
// Ignore all the other eventTypes, but you should consider the other ones.
}
}
When I use this code It can't display anything in jTextArea1 .
public void displaySerialData (String data) {
// jTextArea1.append(data);
jTextArea1.append("aaaaa"); // It not show aaaaa
System.out.println(data);
}