I have created a server thread class in netbeans and used the netbeans swing auto generated Jframe to created a GUI application that invokes the class. I want to append a string value from the thread class to my JtextArea, but the value displayed on my Jtextarea is null .The string is not returned Please help me. The code sample is as follows
public class simpletestserver1 extends Thread {
String message,mess;
public void run(){
.
.//some coding here
.
.
DataOutputStream outToClient = new DataOutputStream(c.getOutputStream());
Scanner r = new Scanner(c.getInputStream());
outToClient.writeBytes(m+'\n');
mess=r.nextLine();
// THIS IS THE MESSAGE THAT NEEDS TO BE APPENDED TO
// MY JTEXTAREA IN MY JFRAME CLASS
Now I have another client thread that send data to the server. The server thread has already started to listen when the program runs on another action event. Now,nn a button press action, my client thread start sending data to my server and the text should be appended to my JtextArea the jframe class is as follows:
package sdiappgui;
import java.util.*;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import java.awt.Window;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SendEmail extends javax.swing.JFrame {
public SendEmail() {
initComponents();
}
. //some coding here for other generated components
.at this point my server thread has already started on a previously clicked button action and it is already listening ,i start my client thread and the data sent to server should be appended to my jtextarea
.
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final simpletestserver1 th1=new simpletestserver1();
final simpletestclient1 th2=new simpletestclient2();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
th2.start();
jTextArea2.append("received: " +th1.mess +'\n');
}
});
}
However my jtextarea is not receiving any string returned by the client. A null is displayed on the jtextArea when i run the program. Please help me out.