0

I'm creaitng a client-server application for a small project.

In all of my lectures, both the client and the server were classes which extended JFrame. In other words, the visual-aid was within the same class. I want to know whether it is possible for me to have a JPanel within a JFrame and have the client/server class separate from it. What do I need to do?

I want to separate the GUI from the implementation. In the above paragraph I wanted to say that all of the examples that I have seen implement both the GUI and the server/client interface in the same class. I want to have a GUI class (JPanel) which has elements which interact with functions of the Client/Server...

EDIT: I was talking about self-made MVC(model control view) pattern. I want to separate the view from the model(the server). For this, I need to create a controller class. I was practically asking what the controller clas should be like, but I found an answer; MVC Pattern Description

Mackiavelli
  • 432
  • 2
  • 12
  • This is not duplicate, the question you have posted is totally different from what I am asking. My question is separating the GUI from the client/server implementation. It's not how I can have concurrent input/output. – Mackiavelli Feb 20 '15 at 11:33
  • The [accepted answer](http://stackoverflow.com/a/14617650/230513) illustrates a typical non-GUI `Server` that works with any of the clients discussed. If this is _not_ a duplicate, then your question is unclear. Please edit your question to clarify what's not working; include a [complete example](http://stackoverflow.com/help/mcve) that exhibits any problem you encounter. As an aside, note that many examples extend `JFrame` for no apparent reason. – trashgod Feb 20 '15 at 12:17
  • Man, the question is clear enough. I want to separate my business logic (the server) from the GUI. I don't want them to be the same class. I want them to be 2 classes... – Mackiavelli Feb 20 '15 at 17:23
  • The `Server` & `Client` cited contain no GUI code at all; they are completely separate; it's not clear where you're stuck. If you're asking how to re-factor your existing code, the question is too broad, especially without seeing any code. Have you worked through the relevant [tutorial](http://docs.oracle.com/javase/tutorial/networking/sockets/index.html)? – trashgod Feb 21 '15 at 11:32
  • see the edit, I didn't have a controller class. I was asking how I should construct it. – Mackiavelli Feb 21 '15 at 11:33
  • I can't endorse the cited [tutorial](http://www.tutorialspoint.com/design_pattern/mvc_pattern.htm). As discussed [here](http://stackoverflow.com/a/3072979/230513), the _controller_ should update the _model_; the _model_ then notifies any listening views to update themselves. – trashgod Feb 21 '15 at 12:41
  • So it's okay if I have a reference from the view back to the model(or controller?) I thought that everything should be done within the model. So in my case, this means that I will have a JFrame which has listeners for the things on it, invoking the appropriate controller metods. Then when the controller gets theinformation, it will automatically update the view. Right? – Mackiavelli Feb 21 '15 at 19:30
  • A `JFrame` is a top-level container; individual view components listen to their models. See also this [outline](http://stackoverflow.com/a/2687871/230513) and [discussion](http://stackoverflow.com/a/25556585/230513). – trashgod Feb 22 '15 at 00:37

0 Answers0