[Logo]
Forums Register Login
to print output in textarea
i want to print output in textarea
my output is continuous ,when connection with particular socket is established,which is a reader, it reads continuous tags.
so what i appended the variable in which tha tag value has been stored to text area
but problem is that it is not appending as output is so continuous & variable value is changing continuously

so i am not getting anything in textarea, so what is the way to read fast & continuous output
This should not happen as the JTextArea#append is thread safe.

Can you post your code which demonstrates this problem?
/*
* sam2.java
*
* Created on April 7, 2009, 5:27 PM
*/

package md;

/**
*
* @author Rashilant
*/

import java.lang.String;
import java.net.*;
import java.io.*;
import javax.swing.ComboBoxModel;

public class sam2 extends javax.swing.JFrame {
String us="";
static PrintWriter readerOut = null;
static BufferedReader readerIn = null;

static Socket socket = null;
static int port = 8080;

/** Creates new form sam2 */
public sam2() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jComboBox2 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel3 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMaximizedBounds(new java.awt.Rectangle(0, 0, 100, 100));
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ASTRA", "XTENNA", "ALIEN" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a4(evt);
}
});

jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "192.168.0.101" }));

jButton1.setText("CONNECT");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a1(evt);
}
});

jButton2.setText("START");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a2(evt);
}
});

jButton3.setText("STOP");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a3(evt);
}
});

jLabel1.setText("SELECT IP ADDRESS");

jLabel2.setText("OUTPUT");

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

jLabel3.setText("SELECT READER");

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(35, 35, 35)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jButton1)
.add(jLabel1))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(54, Short.MAX_VALUE)
.add(jLabel2)
.add(42, 42, 42)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(jLabel3)
.add(20, 20, 20)))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(119, 119, 119)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox1, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox2, 0, 128, Short.MAX_VALUE))
.addContainerGap(307, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 541, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(138, 138, 138)
.add(jButton2)
.add(114, 114, 114)
.add(jButton3)))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3))
.add(57, 57, 57)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(63, 63, 63)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2)
.add(jButton1)
.add(jButton3))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(75, 75, 75)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
.addContainerGap())
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel2)
.add(112, 112, 112))))
);
pack();
}// </editor-fold>

private void a3(java.awt.event.ActionEvent evt) {

try {
readerOut.flush();
readerOut.close();
readerIn.close();
socket.close();
} catch (Exception e) {
System.out.println("Exception in TMReaderAdapter.shutdown(): " + e.getMessage());
} finally {
socket = null;
}//end finally
//end shutdown method

jTextArea1.setText("");
// TODO add your handling code here:STOP
}

private void a4(java.awt.event.ActionEvent evt) {

String us1 = (String)jComboBox1.getSelectedItem();
if(us1.equals("ASTRA"))
{
//String msg1[]={"192.168.0.101","a1","a2"};
jComboBox2.removeAllItems();

jComboBox2.addItem("192.168.0.101");

jComboBox2.addItem("192.168.0.181");
jComboBox2.addItem("192.168.0.191");


}

else if(us1.equals("XTENNA"))
{
//String msg1[]={"192.168.0.101","a1","a2"};
jComboBox2.removeAllItems();

jComboBox2.addItem("19");

jComboBox2.addItem("192.");
jComboBox2.addItem("192.1");


}
else if(us1.equals("ALIEN"))
{
//String msg1[]={"192.168.0.101","a1","a2"};
jComboBox2.removeAllItems();

jComboBox2.addItem("192.168");

jComboBox2.addItem("192.168.0");
jComboBox2.addItem("192.168.");


}


// TODO add your handling code here:Combo astra
}

private void a2(java.awt.event.ActionEvent evt) {

//static void get(String us)
String ipaddr;
ipaddr = us;
String command = "";
try {
socket = new Socket(ipaddr, port);
readerOut = new PrintWriter(socket.getOutputStream(), true);
readerIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("connected to RQL socket");

} catch (Exception e) {
System.out.println("Unable to connect to ThingMagic reader: " + e.getMessage());
try {
throw new IOException();
} catch (IOException ex) {
ex.printStackTrace();
}
}//end of catch


System.out.printf ("Connected to reader %s", ipaddr);


command = "SELECT id FROM tag_id;";

System.out.println (command);
//void tellReader(command, true);
//int i=100;

try{
while (true)
{

//command = "UPDATE saved_settings SET tx_power='" + i + "';"; //set the power
//System.out.println (command);
//tellReader(command, true);
command = "SELECT id FROM tag_id;"; //set the power
System.out.println (command);
tellReader(command, true);
Thread.sleep(100);
//i=i+100;

}//end while
}catch (Exception e){
System.out.print ("cmdBuffer Failed!!!");

}//end catch


shutdown();

return;
}//end of main



//Methods
void shutdown() {

try {
readerOut.close();
readerIn.close();
socket.close();
} catch (Exception e) {
System.out.println("Exception in TMReaderAdapter.shutdown(): " + e.getMessage());
} finally {
socket = null;
}//end finally
}//end shutdown method

/*void stopdown(String newtag) {
jTextArea1.append("Response tag is ===== "+newtag+"\n");


}*/
//Pass RQL commands to reader and wait for response
void tellReader (String cmd, boolean getResponse) throws IOException {
String data;

System.out.println("Tell reader: " + cmd);
jTextArea1.append("tell reader"+cmd+"\n");
try {
readerOut.println(cmd); // Send command to reader
} catch (Exception e) {
System.out.println("Exception sending command to ThingMagic reader: " + e.getMessage());
throw new IOException();
}

if (!getResponse)
return;
while (true) { // Loop until success or error. Ignore data
try {
data = readerIn.readLine();
} catch (Exception e) {
System.out.println("Exception reading command from ThingMagic reader: " + e.getMessage());
throw new IOException();
}

if (data.length() == 0)
return;
// success
String newtag=data.substring(2,26) ;
System.out.println("Response tag is ===== " + newtag);

jTextArea1.append("Response tag is ===== "+newtag+"\n");
if (data.length() >= 5) {
if (data.startsWith("Error")) {
System.out.println("Response= " + data);
throw new IOException();
}
}
// stopdown(newtag);

// return;
}
//TextArea1.
//}

// TODO add your handling code here:start

}

private void a1(java.awt.event.ActionEvent evt) {

us = (String)jComboBox2.getSelectedItem();


//ps=Integer.ParseInt(jTextField2.getText());
try{

Socket s=new Socket(us,8080);
System.out.println("connected");
jTextArea1.setText("connected\n");


}
catch(Exception x){
}
// TODO add your handling code here:connect
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new sam2().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration

}
Sam,
When I said "code which demonstrates this problem", I meant http://homepage1.nifty.com/algafield/sscce.html

Also please use code tags
> i want to print output in textarea

this might be an example of what you're trying to do

http://codeguru.earthweb.com/java/articles/382.shtml

it's an awt app, but easily converted to swing

This thread has been viewed 4059 times.

All times above are in ranch (not your local) time.
The current ranch time is
Sep 26, 2018 00:54:32.