10 Replies - 411 Views - Last Post: 18 June 2019 - 10:16 AM Rate Topic: -----

#1 Umika155   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-June 19

I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 10:49 AM

Hi, I'm trying to send inputs from Client JForm to Server JForm through socket connection. But only one input (ipaddress) that is passed but it's not populate the Jtable. There's no error shows. Only the JTable is empty and the textfield in server is sending message that the client is connected.

This is the Client side code:
public class ClientForm extends JFrame {

    String username, address = "localhost";
    String ipAddress, gunName, softVersion, devType;
    
    ArrayList<String> users = new ArrayList();
    int port = 2222;
    Boolean isConnected = false;
    
    Socket sock;
    BufferedReader reader;
    PrintWriter writer;
    
    public void ListenThread() 
    {
         Thread IncomingReader = new Thread(new IncomingReader());
         IncomingReader.start();
    }
    
    //add users to the arraylist
    public void userAdd(String data) 
    {
         users.add(txtIPAddress.getText());
         users.add(txtGunName.getText());
         users.add(txtSoftwareVersion.getText());
         users.add(txtDeviceType.getText());
    }
    
    public class IncomingReader implements Runnable
    {
        @Override
        public void run() 
        {
            String[] data;
            String stream, done = "Done", connect = "Connect", disconnect = "Disconnect";
            
            try 
            {
                while ((stream = reader.readLine()) != null) 
                {
                     data = stream.split(":");

                     if (data[2].equals(connect)) // if user click connect
                     {
                        ta_client.append("Connected to Server");
                        userAdd(data[0]);// add user to arraylist to send to the server
                     } 
                     else if (data[2].equals(disconnect)) 
                     {
                         userRemove(data[0]);
                     } 
                     else if (data[2].equals(done)) 
                     {
                        writeUsers();
                        users.clear();
                     }
                }
           }catch(Exception ex) { }
        
        }
    }
                     
//Button to send message to the server. This message will appear in the row as the ipaddress connected but it's not even showing to the textfield nor do I get any error message
    private void btnSendMsgActionPerformed(java.awt.event.ActionEvent evt) {                                           
        String nothing = "";
        if ((txtMsg.getText()).equals(nothing)) {
            txtMsg.setText("");
            txtMsg.requestFocus();
        } else {
            try {
               writer.println(username + ":" + txtMsg.getText());
               writer.flush(); // flushes the buffer
            } catch (Exception ex) {
                ta_client.append("Message was not sent. \nError: " + ex);
            }
            txtMsg.setText("");
            txtMsg.requestFocus();
        }

        txtMsg.setText("");
        txtMsg.requestFocus();
    }                                          

// When the client click connect button after fill up the clients detail, it will create connection and send the inputs to server.
    private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {                                           
        if (isConnected == false) 
        {
            username = txtIPAddress.getText(); 
            txtIPAddress.setEditable(false);

            try 
            {
                sock = new Socket(address, port);
                InputStreamReader streamreader = new InputStreamReader(sock.getInputStream());
                reader = new BufferedReader(streamreader);
                writer = new PrintWriter(sock.getOutputStream());
                writer.println(username + ": has connected."); //send who is connected
                writer.flush(); 
                isConnected = true; 
            } 
            catch (Exception ex) 
            {
                ta_client.append("Cannot Connect! Try Again. \nError: " + ex);
                txtIPAddress.setEditable(true);
            }
            
            ListenThread();
            
        } else if (isConnected == true) 
        {
            ta_client.append("You are already connected. \n");
        }
    }             




This is the server side:

public class ServerForm extends JFrame {
    
    ArrayList clientOutputStreams;
    ArrayList<String> users;
    
    public class ClientHandler implements Runnable{
        BufferedReader reader;
        Socket sock;
        PrintWriter client;
        String clientName = "";
       
        
        public String getIPAddress(){
            return clientName;
        }

        @Override
        public void run() {
            String message, connect = "Connect", disconnect = "Disconnect";
            String[] data;
            
            try 
            {
                while ((message = reader.readLine()) != null) 
                {
                    txtAreaOutput.append("Received: " + message + "\n");
                    data = message.split(": ");
                    
                    for (String token:data) 
                    {
                        txtAreaOutput.append(token + "\n");
                    }

                    if (data[2].equals(connect)) //if client connect, send msg to textfield the client is connected and send inputs to JTable.
                    {
                        tellEveryone((data[0] + ": " + data[1])); 
                        txtAreaOutput.append("User added -> "+getIPAddress());
                        addToTable(data[0] + data[1] + data[2] + data[3]); //not working. 
                    } 
                    else if (data[2].equals(disconnect)) 
                    {
                        tellEveryone((data[0] + ": has disconnected."));
                        userRemove(data[0]);
                    } 
                    else 
                    {
                        txtAreaOutput.append("No Conditions were met. \n");
                    }
                } 
             } 
             catch (Exception ex) 
             {
                txtAreaOutput.append("Lost a connection. \n");
                ex.printStackTrace();
                clientOutputStreams.remove(client);
             } 
        }
        
    }

public class ServerStart implements Runnable 
    {
        @Override
        public void run() 
        {
            clientOutputStreams = new ArrayList();
            users = new ArrayList();  

            try 
            {
                //socket connection
            }
            catch (Exception ex)
            {
                txtAreaOutput.append("Error making a connection. \n");
            }
        }
    }

     
     //add client input to jtable but nothing work
    public void addToTable(String[] data){
            
        String[] ipaddr = data; 
        String done = "Server: DONE";
        txtAreaOutput.append("Adding new client: " + ipaddr + "\n");
        
        DefaultTableModel dt = (DefaultTableModel) listClients.getModel();
        dt.addRow(data);
 
        tellEveryone(done);
    }
     
     

    
     public void tellEveryone(String message) 
    {
	//send msg to the textfield
    }




I've tried to Google and tried any similar thing but nothing works.
Attached is sample GUI.

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: I cannot send the inputs from Client to a JTable in Server JForm

#2 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 02:58 PM

Can you post the import statements needed to compile the code for testing?

Also there are many missing variable definitions causing lots of compiler errors.

This post has been edited by NormR: 17 June 2019 - 04:14 PM

Was This Post Helpful? 0
  • +
  • -

#3 Umika155   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-June 19

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 07:52 PM

View PostNormR, on 17 June 2019 - 02:58 PM, said:

Can you post the import statements needed to compile the code for testing?

Also there are many missing variable definitions causing lots of compiler errors.


I left out any unnecessary as I didn't get any error. And I'm using netbeans so it has already automatically declare the swing Jframe components.
Below is the full code:

Client side
import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

public class ClientForm extends JFrame {

    String username, address = "localhost";
    String ipAddress, gunName, softVersion, devType;
    
    ArrayList<String> users = new ArrayList();
    int port = 2222;
    Boolean isConnected = false;
    
    Socket sock;
    BufferedReader reader;
    PrintWriter writer;
    
    public void ListenThread() 
    {
         Thread IncomingReader = new Thread(new IncomingReader());
         IncomingReader.start();
    }
    
    //add users to the arraylist
    public void userAdd(String data) 
    {
         users.add(txtIPAddress.getText());
         users.add(txtGunName.getText());
         users.add(txtSoftwareVersion.getText());
         users.add(txtDeviceType.getText());
    }
    
    public void userRemove(String data) 
    {
         ta_client.append(data + " is now offline.\n");
    }
    
    public void writeUsers() 
    {
         String[] tempList = new String[(users.size())];
         users.toArray(tempList);
         for (String token:tempList) 
         {
             //users.append(token + "\n");
         }
    }
    
    public void sendDisconnect() 
    {
        String bye = (username + ": : Disconnect");
        try
        {
            writer.println(bye); 
            writer.flush(); 
        } catch (Exception e) 
        {
            ta_client.append("Could not send Disconnect message.\n");
        }
    }
    
    public void Disconnect() 
    {
        try 
        {
            ta_client.append("Disconnected.\n");
            sock.close();
        } catch(Exception ex) {
            ta_client.append("Failed to disconnect. \n");
        }
        isConnected = false;
        txtIPAddress.setEditable(true);

    }
    
    
    public ClientForm() {
        initComponents();
    }
    
    public class IncomingReader implements Runnable
    {
        @Override
        public void run() 
        {
            String[] data;
            String stream, done = "Done", connect = "Connect", disconnect = "Disconnect";
            
            try 
            {
                while ((stream = reader.readLine()) != null) 
                {
                     data = stream.split(":");

                     if (data[2].equals(connect)) // if user click connect
                     {
                        ta_client.append("Connected to Server");//.removeAll();
                        userAdd(data[0]);// add user to arraylist
                        //ta_client.append("User data is: " + userAdd(data));
                     } 
                     else if (data[2].equals(disconnect)) 
                     {
                         userRemove(data[0]);
                     } 
                     else if (data[2].equals(done)) 
                     {
                        //users.setText("");
                        writeUsers();
                        users.clear();
                     }
                }
           }catch(Exception ex) { }
        
        }
    }
    
private void btnSendMsgActionPerformed(java.awt.event.ActionEvent evt) {                                           
        String nothing = "";
        if ((txtMsg.getText()).equals(nothing)) {
            txtMsg.setText("");
            txtMsg.requestFocus();
        } else {
            try {
               writer.println(username + ":" + txtMsg.getText());
               writer.flush(); // flushes the buffer
            } catch (Exception ex) {
                ta_client.append("Message was not sent. \nError: " + ex);
            }
            txtMsg.setText("");
            txtMsg.requestFocus();
        }

        txtMsg.setText("");
        txtMsg.requestFocus();
    }                                          

    private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {                                           
        if (isConnected == false) 
        {
            username = txtIPAddress.getText(); 
            txtIPAddress.setEditable(false);

            try 
            {
                sock = new Socket(address, port);
                InputStreamReader streamreader = new InputStreamReader(sock.getInputStream());
                reader = new BufferedReader(streamreader);
                writer = new PrintWriter(sock.getOutputStream());
                writer.println(username + ": has connected.");
                writer.flush(); 
                isConnected = true; 
            } 
            catch (Exception ex) 
            {
                ta_client.append("Cannot Connect! Try Again. \nError: " + ex);
                txtIPAddress.setEditable(true);
            }
            
            ListenThread();
            
        } else if (isConnected == true) 
        {
            ta_client.append("You are already connected. \n");
        }
    }                                          

    private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {                                              
        sendDisconnect();
        Disconnect();
    }                                             

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClientForm().setVisible(true);
            }
        });
    }




Server side:
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author SOFTWAREDEVELOPER
 */
public class ServerForm extends javax.swing.JFrame {
    
    ArrayList clientOutputStreams;
    ArrayList<String> users;
    //Vector<String> clientdata = new Vector<String>();
    
    public class ClientHandler implements Runnable{
        BufferedReader reader;
        Socket sock;
        PrintWriter client;
        String clientName = "";
        
        public ClientHandler(Socket clientSocket, PrintWriter user) 
       {
            client = user;
            try 
            {
                sock = clientSocket;
                InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
                reader = new BufferedReader(isReader);
            }
            catch (Exception ex) 
            {
                txtAreaOutput.append("Unexpected error... \n");
            }

       }
        
        public String getIPAddress(){
            return clientName;
        }

        @Override
        public void run() {
            String message, connect = "Connect", disconnect = "Disconnect";
            String[] data;
            
            try 
            {
                while ((message = reader.readLine()) != null) 
                {
                    txtAreaOutput.append("Received: " + message + "\n");
                    data = message.split(": ");
                    
                    for (String token:data) 
                    {
                        txtAreaOutput.append(token + "\n");
                    }

                    if (data[2].equals(connect)) 
                    {
                        tellEveryone((data[0] + ": " + data[1]));
                        txtAreaOutput.append("User added -> "+getIPAddress());
                        //addToTable(data[0] + data[1] + data[2] + data[3]);
                    } 
                    else if (data[2].equals(disconnect)) 
                    {
                        tellEveryone((data[0] + ": has disconnected."));
                        userRemove(data[0]);
                    } 
                    else 
                    {
                        txtAreaOutput.append("No Conditions were met. \n");
                    }
                } 
             } 
             catch (Exception ex) 
             {
                txtAreaOutput.append("Lost a connection. \n");
                ex.printStackTrace();
                clientOutputStreams.remove(client);
             } 
        }
        
    }
    
    
    public ServerForm() {
        initComponents();
    }

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

        Thread starter = new Thread(new ServerStart());
        starter.start();
        
        txtAreaOutput.append("Server started...\n");
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ServerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ServerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ServerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ServerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ServerForm().setVisible(true);
            }
        }); 
    }
    
     public class ServerStart implements Runnable 
    {
        @Override
        public void run() 
        {
            clientOutputStreams = new ArrayList();
            users = new ArrayList();  

            try 
            {
                ServerSocket serverSock = new ServerSocket(2222);

                while (true) 
                {
				Socket clientSock = serverSock.accept();
				PrintWriter writer = new PrintWriter(clientSock.getOutputStream());
				clientOutputStreams.add(writer);

				Thread listener = new Thread(new ClientHandler(clientSock, writer));
				listener.start();
				txtAreaOutput.append("Got a connection. \n");
                }
            }
            catch (Exception ex)
            {
                txtAreaOutput.append("Error making a connection. \n");
            }
        }
    }

    @Override
    public void pack() {
        super.pack(); //To change body of generated methods, choose Tools | Templates.
    }
     
     //add client input to jtable
    public void addToTable(String[] data){
            
        String[] ipaddr = data; 
        String done = "Server: DONE";
        txtAreaOutput.append("Adding new client: " + ipaddr + "\n");
        
        DefaultTableModel dt = (DefaultTableModel) listClients.getModel();
       dt.addRow(data);
 
        tellEveryone(done);
    }
     
     
    public void userRemove (String data) 
    {
        String message, add = ": :Connect", done = "Server: :Done", name = data;
        users.remove(name);
        String[] tempList = new String[(users.size())];
        users.toArray(tempList);

        for (String token:tempList) 
        {
            message = (token + add);
            tellEveryone(message);
        }
        tellEveryone(done);
    }
    
     public void tellEveryone(String message) 
    {
	Iterator it = clientOutputStreams.iterator();

        while (it.hasNext()) 
        {
            try 
            {
                PrintWriter writer = (PrintWriter) it.next();
		writer.println(message);
		txtAreaOutput.append("Sending: " + message + "\n");
                writer.flush();
                txtAreaOutput.setCaretPosition(txtAreaOutput.getDocument().getLength());

            } 
            catch (Exception ex) 
            {
		txtAreaOutput.append("Error telling everyone. \n");
            }
        } 
    }


Was This Post Helpful? 0
  • +
  • -

#4 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 49
  • View blog
  • Posts: 679
  • Joined: 23-September 15

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 08:07 PM

You are not define txtAreaOutput
Was This Post Helpful? 0
  • +
  • -

#5 Umika155   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-June 19

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 08:14 PM

View Postwseng92, on 17 June 2019 - 08:07 PM, said:

You are not define txtAreaOutput


I'm using NetBeans and it's already defined. There's no compiler error. I didn't get any exception error too. It's just it didn't show at the server side the inputs from client.
private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listClients = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        btnSendtoSelect = new javax.swing.JButton();
        btnSendtoAll = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAreaOutput = new javax.swing.JTextArea();
        btnStart = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
        jLabel1.setText("Laser Tag System Server");

        listClients.setAutoCreateRowSorter(true);
        listClients.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null}
            },
            new String [] {
                "IP Address", "Gun Name", "Software", "Last Seen", "Device Type", "Message Received"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        listClients.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(listClients);

        jLabel2.setText("1st Value to Send:");

        jLabel3.setText("2nd Value to Send:");

        jLabel4.setText("3rd Value to Send:");

        btnSendtoSelect.setText("Send to Selected Gun");
        btnSendtoSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendtoSelectActionPerformed(evt);
            }
        });

        btnSendtoAll.setText("Send to All Gun");
        btnSendtoAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendtoAllActionPerformed(evt);
            }
        });

        jLabel5.setText("Communication Log:");

        txtAreaOutput.setColumns(20);
        txtAreaOutput.setRows(5);
        jScrollPane2.setViewportView(txtAreaOutput);

        btnStart.setText("Server Start");
        btnStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 789, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(116, 116, 116)
                        .addComponent(btnStart))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addGap(34, 34, 34)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnSendtoSelect)
                                .addGap(18, 18, 18)
                                .addComponent(btnSendtoAll)))
                        .addGap(99, 99, 99)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addGap(23, 53, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(btnStart))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnSendtoSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnSendtoAll, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(119, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        


// Variables declaration - do not modify                     
    private javax.swing.JButton btnSendtoAll;
    private javax.swing.JButton btnSendtoSelect;
    private javax.swing.JButton btnStart;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTable listClients;
    private javax.swing.JTextArea txtAreaOutput;
    // End of variables declaration       


Was This Post Helpful? 0
  • +
  • -

#6 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 49
  • View blog
  • Posts: 679
  • Joined: 23-September 15

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 08:21 PM

Ok. Can you send the initComponents() for client side as well?

Quote

But only one input (ipaddress) that is passed

Between, which line is sending input to Server form?

This post has been edited by wseng92: 17 June 2019 - 08:25 PM

Was This Post Helpful? 0
  • +
  • -

#7 Umika155   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-June 19

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 17 June 2019 - 08:44 PM

View Postwseng92, on 17 June 2019 - 08:21 PM, said:

Ok. Can you send the initComponents() for client side as well?

Quote

But only one input (ipaddress) that is passed

Between, which line is sending input to Server form?



Client initcomponents
private void initComponents() {

        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        txtIPAddress = new javax.swing.JTextField();
        txtGunName = new javax.swing.JTextField();
        txtSoftwareVersion = new javax.swing.JTextField();
        txtDeviceType = new javax.swing.JTextField();
        lblMainTitle = new javax.swing.JLabel();
        lblTitle = new javax.swing.JLabel();
        lblIPAddress = new javax.swing.JLabel();
        lblGunName = new javax.swing.JLabel();
        lblSoftwareVer = new javax.swing.JLabel();
        lblDeviceType = new javax.swing.JLabel();
        btnConnect = new javax.swing.JButton();
        btnDisconnect = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        ta_client = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        txtMsg = new javax.swing.JTextField();
        btnSendMsg = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtServerIPAdd = new javax.swing.JTextPane();

        jFormattedTextField1.setText("jFormattedTextField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblMainTitle.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
        lblMainTitle.setText("Laser Tag Device Simulator");

        lblTitle.setText("Connection Detail: ");
        lblTitle.setToolTipText("");

        lblIPAddress.setText("Server IP Address:");

        lblGunName.setText("Gun Name:");

        lblSoftwareVer.setText("Software Version:");

        lblDeviceType.setText("Device Type:");

        btnConnect.setText("Connect");
        btnConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConnectActionPerformed(evt);
            }
        });

        btnDisconnect.setText("Disconnect");
        btnDisconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDisconnectActionPerformed(evt);
            }
        });

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

        jLabel1.setText("Communication Log:");

        btnSendMsg.setText("Send Message");
        btnSendMsg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendMsgActionPerformed(evt);
            }
        });

        jScrollPane2.setViewportView(txtServerIPAdd);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblMainTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblIPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblGunName, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblSoftwareVer, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblDeviceType, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtDeviceType, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtSoftwareVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtGunName, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtIPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(lblTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(125, 125, 125)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(27, 27, 27)
                                        .addComponent(btnSendMsg))))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(btnConnect, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(btnDisconnect, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMainTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTitle)
                    .addComponent(jLabel1))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(79, 79, 79)
                                .addComponent(lblSoftwareVer))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblIPAddress)
                                .addGap(26, 26, 26)
                                .addComponent(lblGunName)))
                        .addGap(46, 46, 46))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtIPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtGunName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtSoftwareVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDeviceType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblDeviceType))
                        .addGap(8, 8, 8))
                    .addComponent(jScrollPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMsg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSendMsg))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnConnect)
                    .addComponent(btnDisconnect))
                .addGap(74, 74, 74)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold> 

// Variables declaration - do not modify                     
    private javax.swing.JButton btnConnect;
    private javax.swing.JButton btnDisconnect;
    private javax.swing.JButton btnSendMsg;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblDeviceType;
    private javax.swing.JLabel lblGunName;
    private javax.swing.JLabel lblIPAddress;
    private javax.swing.JLabel lblMainTitle;
    private javax.swing.JLabel lblSoftwareVer;
    private javax.swing.JLabel lblTitle;
    private static javax.swing.JTextArea ta_client;
    private javax.swing.JTextField txtDeviceType;
    private javax.swing.JTextField txtGunName;
    private javax.swing.JTextField txtIPAddress;
    private javax.swing.JTextField txtMsg;
    private static javax.swing.JTextPane txtServerIPAdd;
    private javax.swing.JTextField txtSoftwareVersion;
    // End of variables declaration        




in client side at line 98 using userAdd where useradd will add the inputs from textfield to the arraylist.
But I think this is wrong. I actually want it to send the inputs when button "Connect" is click but I can only send username = ipaddress to the server but not all textfield inputs.
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3638
  • View blog
  • Posts: 16,706
  • Joined: 20-September 08

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 18 June 2019 - 03:08 AM

It's not likely to work as there is insufficient coordination of your worker threads and the gui threads. Have a look at the api docs for SwingWorker and see how it is used and what it is used for. It will likely be your best solution
Was This Post Helpful? 0
  • +
  • -

#9 Umika155   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-June 19

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 18 June 2019 - 05:24 AM

View Postg00se, on 18 June 2019 - 03:08 AM, said:

It's not likely to work as there is insufficient coordination of your worker threads and the gui threads. Have a look at the api docs for SwingWorker and see how it is used and what it is used for. It will likely be your best solution


Please excuse me but I don't know much about swing. Is there any suggestion on solving this using arraylist or vector method?
Was This Post Helpful? 0
  • +
  • -

#10 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3638
  • View blog
  • Posts: 16,706
  • Joined: 20-September 08

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 18 June 2019 - 06:32 AM

Quote

Please excuse me but I don't know much about swing. Is there any suggestion on solving this using arraylist or vector method?

Well, you need to get into the position where you do ;) Otherwise you won't get it working. It's got nothing to do with collection classes. It's a matter of thread coordination and the event dispatch queue
Was This Post Helpful? 1
  • +
  • -

#11 Umika155   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-June 19

Re: I cannot send the inputs from Client to a JTable in Server JForm

Posted 18 June 2019 - 10:16 AM

View Postg00se, on 18 June 2019 - 06:32 AM, said:

Quote

Please excuse me but I don't know much about swing. Is there any suggestion on solving this using arraylist or vector method?

Well, you need to get into the position where you do ;)/> Otherwise you won't get it working. It's got nothing to do with collection classes. It's a matter of thread coordination and the event dispatch queue


I see.. okay. thank you for your explanation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1