title: java GUI multi-threading with socket
body: <p>I am trying to make a GUI program which get data from TCP socket.
  The problem is when I set up the socket, and then start it, GUI program freeze. 
  I want add one more function that stop thread by using click event. </p>
  
  <p>As I know I have to use EDT, I tried but doesn't work. Is there anyone who can help me?</p>
  
  <p>Here's my code.</p>
  
  <ol>
  <li><p>main</p>
  
  <pre><code>public class ImageSplit {  
  static ImageViewerFrame program;
  public static void main(String[] args) throws IOException {  
  JPanel[] displayArray = new JPanel[100];   
  program = new ImageViewerFrame();
  
  EventQueue.invokeLater(new Runnable(){
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
          program.setVisible(true);
      }
  
  });
  } 
  </code></pre></li>
  <li><p>frame</p>
  
  <pre><code>void createMouseMenu() {
  final PopupMenu menu = new PopupMenu();
  MenuItem grid = new MenuItem("Grid");
  MenuItem start = new MenuItem("Start");
  MenuItem stop = new MenuItem("Stop");
  menu.add(grid);
  menu.add(start);
  menu.add(stop);
  add(menu);
  
  mouseMenuHandler mousemenu = new mouseMenuHandler();
  
  grid.addActionListener(mousemenu);
  start.addActionListener(mousemenu);
  stop.addActionListener(mousemenu);
  
  addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
          if (e.getModifiers() == InputEvent.BUTTON3_MASK)
              menu.show(e.getComponent(), e.getX(), e.getY());
      }
  });
     }
  class mouseMenuHandler implements ActionListener {
  getInfo info;
  
  public void actionPerformed(ActionEvent e) {// open grid setting
      if (e.getActionCommand().equals("Grid")) {
          gridSettingUI = new GridSetting(img);
          gridSettingUI.setVisible(true);
      } else if (e.getActionCommand().equals("Start")) {
          try {
              info = new getInfo(40000);//open socket
              info.run();
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
      } else if (e.getActionCommand().equals("Stop")) {
          System.out.println("stop");
          info.stop();
      }
  }
  }
  </code></pre></li>
  <li><p>socket Receiving</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.net.ServerSocket;
  import java.net.Socket;
  
  
  
  public class getInfo implements Runnable{
  ServerSocket serverSocket;
  private boolean stopped=false;
  
  public getInfo(int port_num) throws IOException{
  serverSocket = new ServerSocket(port_num);
  }
  @Override
  public void run() {
  // TODO Auto-generated method stub
  while(!stopped){
  try {
  Socket socket = serverSocket.accept();
  System.out.println(socket.getInetAddress()+ "connected");
  
  InputStream is = socket.getInputStream();
  InputStreamReader isr = new InputStreamReader(is);
  BufferedReader br = new BufferedReader(isr);
  if(br.ready())
  {
  String line = br.readLine();
  System.out.println(line+"\n");
  }
  } catch (IOException e) {
  // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  }
  
  public void stop(){
  stopped = true;        
  }
  </code></pre></li>
  </ol>
  
  <p>}</p>