gt:                     StringTokenizer fields = new StringTokenizer(entry, " ");
context: /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package network;
  
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.net.Socket;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.StringTokenizer;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.JLabel;
  import javax.swing.SwingUtilities;
  
  /**
   *
   * @author Raffan
   */
  public class ServerThread implements Runnable{
      
     public NewJFrame frame;
     private ObjectOutputStream output; // output stream to client
     private ObjectInputStream input; // input stream from client
     //private ServerSocket server; // server socket
     private Socket connection;
     private Thread thr;
     public String clientType = "";
     public int isConnected, actualEntry;
     
     public ServerThread(NewJFrame obj, Socket socket)
     {
          frame = obj;
          connection = socket;
          this.thr = new Thread(this);
  	thr.start();
     }
      public void run() {
          try {
              getStreams();
              processConnection();
          } catch (IOException ex) {
              Logger.getLogger(ServerThread.class.getName()).log(Level.SEVERE, null, ex);
          }
          finally
          {
              closeConnection();
          }
      }
      
      private void getStreams() throws IOException
      {
        // set up output stream for objects
        output = new ObjectOutputStream( connection.getOutputStream() );
        output.flush(); // flush output buffer to send header information
  
        // set up input stream for objects
        input = new ObjectInputStream( connection.getInputStream() );
  
        displayMessage( "\nGot I/O streams\n" );
     } // end method getStreams
  
     // process connection with client
     private void processConnection() throws IOException
     {
           String message = "Connection successful";
           displayMessage( message ); // send connection successful message
  
           try // read message and display it
           {
              message = ( String ) input.readObject(); // read new message
              displayMessage( "\n" + message ); // display message
  
              if(message.equals( "SUBSCRIBER" ))
              {
                  clientType = "SUBSCRIBER";
                  handleSubscriber();
              }            
              else if(message.equals( "SENSOR" ))
              {
                  clientType = "SENSOR";
                  handleSensor(); 
              }   
              else
              {
                  closeConnection();
              }
           } // end try
           catch ( ClassNotFoundException classNotFoundException ) 
           {
              displayMessage( "\nUnknown object type received" );
           } // end catch
  
     } // end method processConnection
  
     
     private void handleSubscriber() throws IOException
     {       
         System.out.println("in subscriber");
         String entry="";       
         
         //System.out.println("in sensor");
         String message = "";
        
        do 
        { 
           try // read message and display it
           {
              message = ( String ) input.readObject(); // read new message            
              //displayMessage( "\n" + message ); // display message
              
              if(message.equals( "REGISTRY" ))
              {
                  try // read message and display it
                   {
                      message = ( String ) input.readObject(); // read new message  
                      displayMessage( "\n" + message );
                   } // end try
                   catch ( ClassNotFoundException classNotFoundException ) 
                   {
                      displayMessage( "\nUnknown object type received" );
                   } // end catch
                 
                  entry = message;
                  isConnected = registry(frame.subscriberList,frame.connectedSubscriberList, entry);
                  
                  if(isConnected >= 0)
                  {
                      frame.refreshLists(frame.connectedSubscriberList, frame.Connected_Subscribers, 1);
                      
                  }
                  
                  
              } 
              else if(message.equals( "SEND CHOICE" ))
              {
                  send_choice();
              }
              else if(message.equals( "UPDATE CHOICE" ))
              {
                  System.out.println("update received");
                  try // read message and display it
                   {
                      message = ( String ) input.readObject(); // read new message  
                      displayMessage( "\n"+message );
                   } // end try
                   catch ( ClassNotFoundException classNotFoundException ) 
                   {
                      displayMessage( "\nUnknown object type received" );
                   }
                  update_choice_list(message);
              }
              else
              {
                  displayMessage("in else");     
                  closeConnection();
                  remove_registry(frame.connectedSubscriberList, entry);
                  frame.refreshLists(frame.connectedSubscriberList, frame.Connected_Subscribers, 1);                
                  isConnected =-1;
                  break;
              
              }
           } // end try
           catch ( ClassNotFoundException classNotFoundException ) 
           {
              displayMessage( "\nUnknown object type received" );
           } // end catch
  
        } while ( true );
     
     }
     
    private void handleSensor() throws IOException
     {
         String entry="";
         JLabel label=null;
         Animator anim = null;
         
         System.out.println("in sensor");
         String message = "",location="",data="";
         
         
        do // process messages sent from client
        { 
           try // read message and display it
           {
              message = ( String ) input.readObject(); // read new message  
              System.out.println("in handle sensor");
              displayMessage( "\n" + message ); // display message
              
              if(message.equals( "DATA" ))
              {
                  System.out.println("in Data......................");
                   try // read message and display it
                   {
                      message = ( String ) input.readObject(); // read new message  
                      displayMessage( "\n"+message );
                   } // end try
                   catch ( ClassNotFoundException classNotFoundException ) 
                   {
                      displayMessage( "\nUnknown object type received" );
                   } // end catch
                  System.out.println("in Data......................after read "+isConnected);
                  data = message;
                  if(isConnected >=0)
                  {
                      update_weather(frame.sensorData, message, actualEntry);
                      notify_subscribers(location,data);
                  }
                 
              }
              
              else if(message.equals( "REGISTRY" ))
              {
                  try // read message and display it
                   {
                      message = ( String ) input.readObject(); // read new message  
                      displayMessage( "\n" + message );
                   } // end try
                   catch ( ClassNotFoundException classNotFoundException ) 
                   {
                      displayMessage( "\nUnknown object type received" );
                   } // end catch
                 
                  
                  entry = message;
                  isConnected = registry(frame.sensorList,frame.connectedSensorList, entry);
                  
                  if(isConnected >= 0)
                  {
                      //geting the location of the sensor
  