java 질문있습니다!! 소스 오류요!!

java 질문있습니다!! 소스 오류요!!

작성일 2009.06.15댓글 2건
    게시물 수정 , 삭제는 로그인 필요

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;

public class ClientComm extends Frame implements ActionListener
{
   private TextArea display;
   private TextField text;
   BufferedWriter output;
   BufferedReader input;
   Socket client;
   String clientdata="";
   String serverdata="";
   public ClientComm(){
     super("클라이언트");
  display = new TextArea("",0,0, TextArea.SCROLLBARS_VERTICAL_ONLY);
  add(display, BorderLayout.CENTER);
  text = new TextField();
  text.addAcionListener(this);
  add(text, BorderLayout.SOUTH);
  addWinowListener(new WinListener());
  setSize(300,150);
  setVisible(true);
}

public void runClient(){
  int counter = 1;
  try
  {
    client = new Socket( InetAddress.getLocalHost(), 1027 );
 display.append("연결된 서버 이름 : " + client.getInetAddress().getHostName());
 input = new BufferedReader(new InputStreamReader(client.getInputStream()));
 output = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
 display.append("\n서버가 보낸 메시지 : "+input.readLine());
  }catch(IOException e){
    e.printStackTrace();
  }
}

public void actioPerformed(ActionEvent ae){
  clientdata = text.getText();
  try{
    output.write( clientdata+"\r\n");
 output.flush();
 text.setText("");
 serverdata = input.readLine();
 display.append("\n서버가 보낸 메시지 : " + serverdata);
 if(serverdata.equals("Bye")){
   display.append("\n송수신 완료." + "연결을 단절한다.\n");
   client.close();
 }
  }catch(IOException e){
    e.printStackTrace();
  }
}

public static void main( String args[] ){
  ClientComm c = new ClientComm();
  c.runClient();
}

class WinListener extends WindowAdapter{
  public void windowClosing(WindowEvent e){
    System.exit(0);
  }
}
}

위에서 6번쨰랑 20번쨰랑 22번째 오류가 뜨는데 무슨 오류인지를 모르겠어요..

제발 도와주세요..ㅠㅠ



profile_image 익명 작성일 -

일단 문제가 있는부분은 빨간색으로 처리하고 이유 설명해놓았습니다.

 

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;

public class ClientComm extends Frame implements ActionListener
{
   private TextArea display;
   private TextField text;
   BufferedWriter output;
   BufferedReader input;
   Socket client;
   String clientdata="";
   String serverdata="";
   public ClientComm(){
     super("클라이언트");
  display = new TextArea("",0,0, TextArea.SCROLLBARS_VERTICAL_ONLY);
  add(display, BorderLayout.CENTER);
  text = new TextField();
  text.addAcionListener(this);  // text.addActionListener(this); 스펠링이 틀렸음 t 가 빠짐
  add(text, BorderLayout.SOUTH);
  addWinowListener(new WinListener()); // addWindowListener(new WinListener());  스펠링이 틀렸음 n 이 빠짐
  setSize(300,150);
  setVisible(true);
}

public void runClient(){
  int counter = 1;
  try
  {
    client = new Socket( InetAddress.getLocalHost(), 1027 );
 display.append("연결된 서버 이름 : " + client.getInetAddress().getHostName());
 input = new BufferedReader(new InputStreamReader(client.getInputStream()));
 output = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
 display.append("\n서버가 보낸 메시지 : "+input.readLine());
  }catch(IOException e){
    e.printStackTrace();
  }
}

public void actioPerformed(ActionEvent ae){
  clientdata = text.getText();
  try{
    output.write( clientdata+"\r\n");
 output.flush();
 text.setText("");
 serverdata = input.readLine();
 display.append("\n서버가 보낸 메시지 : " + serverdata);
 if(serverdata.equals("Bye")){
   display.append("\n송수신 완료." + "연결을 단절한다.\n");
   client.close();
 }
  }catch(IOException e){
    e.printStackTrace();
  }
}

public static void main( String args[] ){
  ClientComm c = new ClientComm();
  c.runClient();
}

class WinListener extends WindowAdapter{
  public void windowClosing(WindowEvent e){
    System.exit(0);
  }
}

 

public void actionPerformed(ActionEvent arg0) { // 정확한건 모르겠으나 추가해야할듯합니다.
 // TODO Auto-generated method stub
 
}


}

 

//답변확정부탁드립니다.. (__)

profile_image 익명 작성일 -

 

/*
ClientComm.java:6: ClientComm is not abstract and does not override abstract method actionPerformed(java.awt.event.Actio
nEvent) in java.awt.event.ActionListener
public class ClientComm extends Frame implements ActionListener
       ^
ClientComm.java:20: cannot find symbol
symbol  : method addAcionListener(ClientComm)
location: class java.awt.TextField
  text.addAcionListener(this);
      ^
ClientComm.java:22: cannot find symbol
symbol  : method addWinowListener(ClientComm.WinListener)
location: class ClientComm
  addWinowListener(new WinListener());
  ^
3 errors
*/

 

위 에러가 발생한 거구요

 

에러를 확인하니 다 오타때문이더군요

 

해당 로직을 주석처리하고 바로 아래 수정된 메소드명으로 처리하니

정상적으로 처리되더군요.

 

수정된 소스를 아래 올립니다.

 

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;

public class ClientComm extends Frame implements ActionListener
{
   private TextArea display;
   private TextField text;
   BufferedWriter output;
   BufferedReader input;
   Socket client;
   String clientdata="";
   String serverdata="";
   public ClientComm(){
     super("클라이언트");
  display = new TextArea("",0,0, TextArea.SCROLLBARS_VERTICAL_ONLY);
  add(display, BorderLayout.CENTER);
  text = new TextField();
  //text.addAcionListener(this);
  text.addActionListener(this);
  add(text, BorderLayout.SOUTH);
  //addWinowListener(new WinListener());
  addWindowListener(new WinListener());
  setSize(300,150);
  setVisible(true);
}

public void runClient(){
  int counter = 1;
  try
  {
    client = new Socket( InetAddress.getLocalHost(), 1027 );
 display.append("연결된 서버 이름 : " + client.getInetAddress().getHostName());
 input = new BufferedReader(new InputStreamReader(client.getInputStream()));
 output = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
 display.append("\n서버가 보낸 메시지 : "+input.readLine());
  }catch(IOException e){
    e.printStackTrace();
  }
}

//public void actioPerformed(ActionEvent ae){
public void actionPerformed(ActionEvent ae){
  clientdata = text.getText();
  try{
    output.write( clientdata+"\r\n");
 output.flush();
 text.setText("");
 serverdata = input.readLine();
 display.append("\n서버가 보낸 메시지 : " + serverdata);
 if(serverdata.equals("Bye")){
   display.append("\n송수신 완료." + "연결을 단절한다.\n");
   client.close();
 }
  }catch(IOException e){
    e.printStackTrace();
  }
}

 

public static void main( String args[] ){
  ClientComm c = new ClientComm();
  c.runClient();
}

class WinListener extends WindowAdapter{
  public void windowClosing(WindowEvent e){
    System.exit(0);
  }
}
}

 

 

 

즐프하시기 바랍니다.

java 문법 array 관련 질문있습니다.

... i++ ) { num[i]= @@ } public int getnum (int index) { return num[index];} 대충 이런 식으로 짜면 자꾸 오류가 뜨더라구요 ㅠㅠ 전체 소스가 아니라...

자바 초보 질문있습니다.

... printIn("안녕"); } } 뭐가 문제인지 모르겠는데 오류... java file 이게 체크가 되어있습니다. 이 부분을 체크 해제하시고 프로젝트를 만들고 다시 똑같이 소스...