12.07.2015 Views

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

185 CHAT K192223 Scanner entrada = new Scanner ( socket . getInputStream ());24 PrintStream saida = new PrintStream ( socket . getOutputStream ());2526 Receptor receptor = new Receptor ( entrada , this . distribuidor );27 Thread pilha = new Thread ( receptor );28 pilha . start ();2930 Emissor emissor = new Emissor ( saida );3132 this . distribuidor . adicionaEmissor ( emissor );3334 } catch ( IOException e) {35 System . out . println (" ERRO ");36 }37 }38 }39 }Código Java E.10: Registrador.java7 No projeto K19-chat-server crie uma classe para inicializar o servidor.1 import java .io. IOException ;2 import java . net . ServerSocket ;34 public class Server {5 public static void main ( String [] args ) throws IOException {6 Distribuidor distribuidor = new Distribuidor ();78 ServerSocket serverSocket = new ServerSocket (10000) ;910 Registrador registrador = new Registrador ( distribuidor , serverSocket );11 Thread pilha = new Thread ( registrador );12 pilha . start ();13 }14 }Código Java E.11: Server8 No projeto K19-chat-client crie uma classe para <strong>de</strong>finir o emissor <strong>de</strong> mensagens.1 import java .io. PrintStream ;23 public class EmissorDeMensagem {4 private PrintStream saida ;56 public EmissorDeMensagem ( PrintStream saida ) {7 this . saida = saida ;8 }910 public void envia ( String mensagem ) {11 this . saida . println ( mensagem );12 }13 }Código Java E.12: EmissorDeMensagem.java9 No projeto K19-chat-client crie uma classe para <strong>de</strong>finir a tela em Java Swing do chat.1 import java . awt . event . ActionEvent ;2 import java . awt . event . ActionListener ;34 import javax . swing . JButton ;5 import javax . swing . JFrame ;6 import javax . swing . JLabel ;www.<strong>k19</strong>.com.br 185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!