application server/client with gui
<p>I would create an application server/client with a gui in java but I have not clear how I can organize the class. I created the application gui:</p>

<p>here it's the code</p>

<pre><code>import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.util.Collection;

public class AziendaGUI implements ActionListener {

private JButton view_list;
private JButton save_list;
private JTextArea text_area;
private JScrollPane scrollpane;
private JPanel pane;

private JFrame frame;
private GridBagLayout grid;

private Azienda company;

public AziendaGUI() {

    company = new Azienda();

    frame = new JFrame("Immobiliari s.p.a");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    view_list = new JButton("View Property");
    view_list.setActionCommand("view_list");
    view_list.addActionListener(this);

    save_list = new JButton("Save List");
    save_list.setActionCommand("save_list");
    save_list.addActionListener(this);

    text_area = new JTextArea();
    scrollpane = new JScrollPane(text_area);
    scrollpane.setPreferredSize(new Dimension(250,350));

    grid = new GridBagLayout();
    pane = new JPanel(grid);

    /* Set Constraints view_list button */
    grid.setConstraints(view_list, new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(5,5,5,5),0,0));
    pane.add(view_list);

    /* Set Constraints save_list button */
    grid.setConstraints(save_list,new GridBagConstraints(1,0,1,1,0.0,0.0,GridBagConstraints.EAST,GridBagConstraints.NONE,new Insets(5,5,5,5),0,0));
    pane.add(save_list);

    /* Set Constraint text area */
    grid.setConstraints(scrollpane, new GridBagConstraints(0,1,2,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(5,5,5,5),0,0));
    pane.add(scrollpane);

    frame.setLayout(new FlowLayout());
    frame.add(pane);

    frame.pack();
    frame.setVisible(true);
}

private void viewList(Collection&lt;Immobile&gt; list){

    text_area.setText(""); //Evita che venga ripetuto tutto il contenuto

    for(Immobile imb : list){

        text_area.append(imb.toString()+"\n");
    }
}

private void store(){

    String file_name = JOptionPane.showInputDialog("Inserisci il nome del file");

    company.store(file_name);
}

@Override
public void actionPerformed(ActionEvent e){

    String s = e.getActionCommand();

    if(s.equals("view_list")){

       viewList(company.getImmobili());
    }
    if(s.equals("save_list")){

        store();
    }
}


public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable(){@Override
                                              public void run(){new AziendaGUI();}});
}
}
</code></pre>

<p>and now this application should works as a server so I have to implement the <code>ServerSocket</code> constructor with all the methods as explained here <a href="http://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html" rel="nofollow">Reading from and Writing to a Socket</a></p>

<p>My question is: where I should implement the server.in the same class AziendaGUI ora I have to create another class and call it in the main of AziendaGUI?</p>
