ObjectOutputStream and Jtable mouseClick setting

77 views Asked by At
 public class Excel01 extends JFrame{
      public static JTable table = new JTable();

     public Excel01() {
         table.addMouseListener(new MouseListener().........


    }
      class PopUp extends JPopupMenu.....
      class SharedListSelectionHandler implements ListSelectionListener
        public static void main(String[] args) {
         Excel01 ex  = new Excel01(); 
         ObjectOutputStream oos = new ObjectOutputStream(soc.getOutputStream());
         oos.writeObject(obj);

     }

 }

I did not include the whole code. but I will explain what I did. as you see I create the class "Excel01" with JFrame extension.

and I made this Excel01 as Object file. and send it to the client whoever connected to my Server.

My question is 1. on client side. pop-up Jtable was successful. and also Server's data but Excel01's table's mouse click event setting was not working on client side.

I'm not really sure what this ObjectoutputStream outputting. If I want to send my mouse event what do I have to do?

1

There are 1 answers

6
GhostCat On

It looks like you are dramatically over-burdening yourself with way too many concepts that have nothing to do with each other.

If you intend to make any progress, you need to dissect those things into the real parts in there:

  • An ObjectOutputStream is used to write java Objects to (read about Java serialization here)
  • A Mouse Event is a UI related "signal" ... there is simply no point in sending that to some remote server

In other words: you should step back and first learn about these different concepts that you intend to use. And then, when you understand the parts, try to use them to solve your problem.

It seems that you want to tell your "server" about something that the client does. Then the answer is not to give the server "the same UI components" and send mouse events there. Then the answer is clearly define the "data" the client is interacting with; and the potential actions one can perform using this client.

And then you define a distinct protocol between client and server; for example some way to send "commands" from the client to the server. The server receives commands, and does something about that.

Example:

  • when your client starts, it might ask the server "send me the data to display"
  • server sends that data, in an efficient manner (could just be serialized java lists, but could also be something else)
  • User works with the client, for example he changes the values within a row
  • Client can now: pre-validate the changes
  • Send a request to the server "update value[x,y]"
  • Server comes back "yes worked" or "no, failed" (then the client could give the user a error message)