Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Socket:How i can set value jtext Field when Client Send Message

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Java Socket:How i can set value jtext Field when Client Send Message

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class M_serverApp extends javax.swing.JFrame implements Runnable {
     
     
        ServerSocket server = null;
        Socket client       = null;
        DataInputStream dis = null;
        DataOutputStream dos = null;
        String m = null;
     
     
        /**
         * Creates new form M_serverApp
         */
        public M_serverApp() {
            initComponents();
     
     
        }
    public void run()
    {
     
        ClientHandler handler = new ClientHandler();
        handler.start(); 
     
    }    
     
     
    class ClientHandler extends Thread{
            public ClientHandler(){
     
     
     
                /******************/
        try {
        server = new ServerSocket(1254);
        System.out.println("start"); 
        }catch(IOException e ){
            System.out.println(e.getMessage());
            System.out.println(e.getStackTrace());
        }
        while (true){
        try{
            client = server.accept();
           // System.out.println("2"); 
     
                dos = new DataOutputStream(client.getOutputStream());
                dis = new DataInputStream(client.getInputStream());
     
     
     
                 m = dis.readUTF();
     
                   System.out.println(m + "***"+client.getInetAddress());
     
     
                   txt2.setEditable(false);
             txt2.setText(m.toString());/***********Here jTextField I Want To Chage*********/
     
     
     
        }catch(IOException e ){
             System.out.print("Error code");
        }
        }
     
                /********************/      
            }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,377
    My Mood
    Mellow
    Thanks
    143
    Thanked 599 Times in 586 Posts

    Default Re: Java Socket:How i can set value jtext Field when Client Send Message

    pseudo code:

    // get the message from the client
    String message = client.getMessage();

    // set the text field to display the message
    textField.setText( message );

Similar Threads

  1. [SOLVED] Can't retrieve Jtext Field values from another frame..
    By mehroz in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 26th, 2014, 01:00 AM
  2. Muliple Client Server chat application..how to send message from server..
    By jesroni in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 14th, 2013, 11:17 PM
  3. Replies: 0
    Last Post: May 31st, 2012, 05:35 PM
  4. Create a JText field upon button click
    By jo15765 in forum AWT / Java Swing
    Replies: 3
    Last Post: May 28th, 2012, 07:06 PM
  5. Replies: 2
    Last Post: March 3rd, 2011, 01:22 PM