채팅 프로그램인데요ㅠㅠjdk 버전문제?
맑은가람
java로 만든 채팅 프로그램입니다..~
handler.java랑 server.java컴파일시 똑같은 곳에서 에러가 나요..
.(chatserver cs,serversocket ss입니다.밑에 표시해두었어요..ㅠ)
class file has wrong version 50.0, should be 49.0
please remove or make sure it appears in the correct subdirectory of the classpath.
이게 에러를 보면 jdk 버전이 다르다고 하는데요
이게 뭔 에런지 잘 모르겠네요
인터넷 검색해보니까 버전이 달라서 그렇다는데...
jdk를 다시 깔아야 하나요???
소스 작성한 곳이랑 저희집 컴이랑 jdk가 5.0이긴 한데 뒤에 붙는 버전이 다른것 같네요ㅠㅠ
jdk다시 까는 방법 외에는 없을까요???
---------------------------chatclient.java-----------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
class chatclient extends jframe implements actionlistener, runnable{
jtextarea ta;
jbutton send;
jtextfield tf;
thread t;
socket so;
bufferedreader br;
printwriter pw;
public chatclient(){
ta = new jtextarea();
send = new jbutton(보내기);
tf = new jtextfield();
jscrollpane sp = new jscrollpane(ta);
jpanel p = new jpanel();
p.setlayout(new borderlayout(1,2));
tf.setbackground(new color(230,245,245));
ta.seteditable(false);
ta.setfont(new font(돋움체,font.bold,18));
tf.setfont(new font(sansserif,font.plain,14));
p.add(center,tf);
p.add(east,send);
brbsp;
this.getcontentpane().add(south,p);
this.add(center,sp);
send.addactionlistener(this); //보내기 버튼
tf.addactionlistener(this);
settitle(채팅 프로그램);
setbounds(500,100,600,300);
setvisible(true);
this.setdefaultcloseoperation(jframe.exit_on_close);
//서버 ip를 입력받는 다이얼로그 생성
string ip = joptionpane.showinputdialog(this,서버 ip를 입력하세요,서버 ip,joptionpane.question_message);
//대화명 입력하는 다이얼로그
string name = joptionpane.showinputdialog(this,대화명을 입력하세요,대화명,joptionpane.information_message);
if(name.length() == 0)
name=손님;
//소켓 설정
try{
so = new socket(ip,9000);
}catch(unknownhostexception ue){
ue.printstacktrace();
}catch(ioexception e){
e.printstacktrace();
}
try{
br = new bufferedreader(new inputstreamreader(so.getinputstream()));
pw = new printwriter(new outputstreamwriter(so.getoutputstream()));
}catch(ioexception e){
e.printstacktrace();
}
//서버에게 대화명 보내기
pw.println(name);
pw.flush();
//thread 생성
t = new thread(this);
t.start();
}
public void actionperformed(actionevent e){
string line=null;
//textfield에 있는 내용 얻어오기
line=tf.gettext();
//서버로 보내기
pw.println(line);
pw.flush(); //버퍼에 있는 내용 비우기
//textfield초기화
tf.settext();
}
public void run(){ // runnable 추상메서드 오버라이드
string line=null;
while(true){
//서버로부터 들어온 내용 읽기
try{
line=br.readline();
}catch(ioexception e){
e.printstacktrace();
}
//textarea 넣기
ta.append(line + \n); // settext는 덮어쓰기가 되므로 쓰면 안된다
int pos =ta.gettext().length();
ta.setcaretposition(pos);
}
}
public static void main(string[] args){
new chatclient();
}
}---------------------------chathandler.java-----------------------------import java.util.*;
import java.io.*;
import java.net.*;
class chathandler extends thread{
chatserver cs;
socket so;
bufferedreader br;
printwriter pw;
public chathandler(chatserver cs, socket so) throws ioexception{ this.cs=cs; this.so=so; br = new bufferedreader(new inputstreamreader(so.getinputstream()));
pw = new printwriter(new outputstreamwriter(so.getoutputstream()));
}
public void run(){
string name = null;
try{
//클라이언트로부터 들어온 대화명 읽기
name = br.readline();
}catch(ioexception e){
e.printstacktrace();
}
//백터에 등록
cs.register(this);
cs.broadcast(name + 님이 입장하셨습니다.);
//대화 시작
string line = null;
font c while(true){
//읽기
try{
line=br.readline(); // 클라이언트로 들어온 내용 읽기.
}catch(ioexception e){
e.printstacktrace();
}
cs.broadcast([ + name + ] + line);
}
}
public printwriter getprintwriter(){
return pw;
}
}