views:

68

answers:

6

I am learning swings for making GUI. I was thinking which is the best possible way in case of socket with swings. 1. The whole swing code goes in the server file. All the handlers and logic in on server side. Client only create socket. 2. The server have logic part. The code for the swing to display interface goes on client side. Client Creates stream to send / rec. data from server.

Whch is the good way out of 2 ?

A: 

What do you mean under 'client' and 'server'? Swing is supposted to be used to develop Desctop (i.e. client-side) applications. Or you are talking about Swing-applets?

Roman
On server i mean ServerSocket Implemntation and on Client Implementation i mean Socket.
asb
+1  A: 

While the options aren't clear to me the way you described them, I will describe what is common practice. Probably the widest adopted (enterprise system) architecture uses some kind of database as a persistence layer, a middle layer with business logic and an interface (either rich client like swing or web interface) containing the view logic.

The client only contains view state-related logic: event processing, notifications, data presentation, data binding etc. Things like data persistence, retrieval, validation are done by sending a request from the interface to the middle layer which then knows how to process the request, processes it and returns any results. This communication usually takes places in the form of web services or session bean method invocations.

Tomislav Nakic-Alfirevic
+2  A: 

The code for the GUI goes on the same machine that the user using the GUI is on; this is almost always the client end of the connection - even server configuration GUIs usually are separate from the server code.

In any case, do not mix the socket code with the GUI code, but use a Model-View-Controller or similar architectural style, isolating the Swing GUI (View), the UI logic (Controller) and the socket code (Model).

Pete Kirkham
A: 

I don't understand the question. Option 1 would display the GUI at the server. Option 2 would display it at the client.

Surely you know where you want the GUI to be displayed? That isn't a Java programming question, it is a business question.

EJP
A: 

Se second option:

2. The server have logic part. The code for the swing to display interface goes on client side. Client Creates stream to send / rec. data from server.

The option 1 is rather complicate and doesn't make much sense.

OscarRyz
A: 

i think the 2nd option is suitable,because the server can be used for processing and the required parameters can be passed to the server that are taken from the user interface on the client side

anusha