Serializing a JFrame and sending via network

后端 未结 4 929
予麋鹿
予麋鹿 2021-01-24 08:03

What I\'m trying to do is to send a JFrame through sockets. The problem is after I send the form and press the button to view it I get the below exception.

4条回答
  •  后悔当初
    2021-01-24 08:31

    It looks like the L&F isn't serializing well, but regardless, my advice again is to instead serialize the GUI's model and send its state through. You can then easily re-create your view with this state, and the amount of data sent will be orders of magnitude less.

    Edit 1: For example, in the code you've posted, you'd create a PersonalData class as your model, that has three String fields for first name, last name, and email, and a boolean (or better enum) field for gender.

    Then the information sent across the socket would be objects of this "model" class, not the whole Swing GUI. You could reproduce the GUI filling in the data from the objects that were passed.

提交回复
热议问题