Socket Cliente

2 respostas
R

sou novo no forum ! :stuck_out_tongue:

entao, to tentando fazer um esquema doido aqui mais nao funfa de jeito nenhum… java é confuso, ou eu sou confuso, sei la =[[ helpa ai ?

CODE

import java.awt.<em>;

import java.awt.event.</em>;

import javax.swing.*;

import java.io.IOException;

import java.io.PrintStream;

import java.net.Socket;
class criaFrame01 {

public static void main(String[] args)

{

Frame f = new Frame();

f.setVisible(true);

}

}

class Frame01 extends JFrame implements ActionListener{

JTextField texto    = new JTextField(32);

JButton    submit   = new JButton(Enviar);

Component  textarea = new TextArea();

String       text;
public Frame01() // Construtor
{
    this.setTitle("Socket Teste");
    this.setSize(470, 250);
  this.setResizable(false);

    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
  
  getContentPane().setLayout(new FlowLayout());

  getContentPane().add(textarea);
  getContentPane().add(texto);
  submit.addActionListener(this); getContentPane().add(submit);

}

}

class connCliente extends Frame01{

public static void main(ActionEvent e){

if(e.getSource() == submit){

ConnCliente con = new ConnCliente();

t.cliente(texto.getText());

}

}
public char cliente(String args[]) {
    Socket sock = null;
    PrintStream stream = null;
  
    try{
        sock = new Socket("127.0.0.1",7000);
        stream = new PrintStream(sock.getOutputStream());
      
        stream.println(text);
      
    }catch(IOException e){
      
        System.out.println("Error 401: Não foi possivel conectar ao servidor.");

    }finally{
        try{
           sock.close();
        }catch(IOException e){}
  
    }

}

}

ta, pode estar estranho, mais é o melhor jeito que eu to achando para fazer tongue.gif

QUOTE(erros)

--------------------Configuration: --------------------

C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:16: Frame01 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener

class Frame01 extends JFrame implements ActionListener{

^

C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:48: cannot resolve symbol

symbol : class ConnCliente

location: class connCliente

ConnCliente con = new ConnCliente();

^

C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:48: cannot resolve symbol

symbol : class ConnCliente

location: class connCliente

ConnCliente con = new ConnCliente();

^

C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:49: non-static variable texto cannot be referenced from a static context

t.cliente(texto.getText());

^

C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:49: cannot resolve symbol

symbol : variable t

location: class connCliente

t.cliente(texto.getText());

^

5 errors

Process completed.

abracos

2 Respostas

_fs

Opa, bem vindo!

Frame01 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener

Você precisa fazer o override do método actionPerformed nas classes que implementam a interface ActionListener.

cannot resolve symbol symbol : class ConnCliente location: class connCliente ConnCliente con = new ConnCliente();
Você colocou o nome da classe com letra minúscula (connCliente).

non-static variable texto cannot be referenced from a static context t.cliente(texto.getText());
Bem, a exceção disse tudo. O que pode fazer é declarar ‘texto’ estático.

annot resolve symbol symbol : variable t
Esse eu vou assumir que você esqueceu de ler esta parte da exceção.

dica1: Swing é difícil cara, desaconselho completamente para você que está começando. Que tal fazer alguns programas só em linha de comando por enquanto?
dica2: Quando vc for postar codigo, tenha do dos nossos pobres olhinhos e coloque-o entre as tags [ code] e [ /code], assim ele fica endentado :smiley:

R

poxa cara muito obrigado mesmo !

consegui resolver quase todos os problemas…

agora esse do:

C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:16: Frame01 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
class Frame01 extends JFrame implements ActionListener{

continua dificil, meu amigo, Isoron recomendou eu a estudar mais OOP, e é isso que irei fazer, novamente obrigado !

qualquercoiisa eu volto aqui
abracos

Criado 6 de abril de 2005
Ultima resposta 6 de abr. de 2005
Respostas 2
Participantes 2