ola pessoal! nao tenho muita experiencia em socket por isso compiei o do livro java como programar 4 edição, mas tah dando um erro no codigo! o erro eh o seguinte: ActionListener cannot be resolved to a type! e o codigo eh esse :
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.(Event).*;
import javax.swing.*;
public class Servidor extends JFrame{
private JTextField enterField;
private JTextArea displayArea;
private ObjectOutputStream output;
private ObjectInputStream input;
private ServerSocket server;
private Socket connection;
private int cont=1;
public Servidor(){
super("Server");
Container container = getContentPane();
enterField = new JTextField();
enterField.setEnabled(false);
enterField.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
sendData( event.getActionCommand());
}
}
);
container.add(enterField, BorderLayout.NORTH);
displayArea= new JTextArea();
container.add(new JScrollPane(displayArea));
setSize(300, 150);
setVisible(true);
}
public void runServidor(){
try {
server = new ServerSocket(5000, 100);
while (true){
waitForConnection();
getStreams();
processConnection();
closeConnection();
++cont;
}
}
catch (EOFException eofExeption){
System.out.println("conexão terminada do cliente");
}
catch (IOException ioExeption){
ioExeption.printStackTrace();
}
}
private void waitForConnection() throws IOException{
displayArea.setText("esperando pela conexão\n");
connection = server.accept();
displayArea.append("conexão" + cont + "recebida de: " +
connection.getInetAddress().getHostName() );
}
private void getStreams() throws IOException{
output = new ObjectOutputStream(
connection.getOutputStream() );
output.flush();
input = new ObjectInputStream(
connection.getInputStream() );
displayArea.append("\nGot I/O streams\n");
}
private void processConnection()throws IOException{
String message = "SERVER>>> connetction successful";
output.writeObject(message);
output.flush();
enterField.setEnabled(true);
do {
try{
message = (String) input.readObject();
displayArea.append("\n" + message);
displayArea.setCaretPosition(
displayArea.getText().length());
}
catch (ClassNotFoundException classNotFoundException){
displayArea.append("recebeu um tipo de obijeto desconhecido");
}
} while (!message.equals("client>>> terminate"));
}
private void closeConnection() throws IOException{
displayArea.append("terminou de usar conexão");
enterField.setEnabled(false);
output.close();
input.close();
connection.close();
}
private void sendData( String message ){
try{
output.writeObject("server>>>" + message);
output.flush();
displayArea.append("\nserver>>>" + message);
}
catch (IOException ioExeption){
displayArea.append("\nerro ao escrever objeto");
}
}
public static void main(String args[]){
Servidor application = new Servidor();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.runServidor();
}
}
agradeço aqueles q puderem tirar minha duvida!
obrigado.