본문내용
if(obj == loginButton) {
id = idInput.getText();
label2.setText("대화명 : " + id);
clayout.show(tab, "logout");
connectServer();
} else if(obj == logoutButton) {
// 로그아웃 메시지 전송
msgOut.setText("");
outMsg.println(id + "/" + "logout");
// 대화 창 클리어
// 로그인 패널로 전환
clayout.show(tab, "login");
outMsg.close();
try {
inMsg.close();
socket.close();
} catch(IOException e) {
e.printStackTrace();
}
status = false;
}
else if(obj == msgInput) {//메세지를 입력할 때
//***************서버로 id, 메시지, 리스트의 인덱스값을 보내줌***************
outMsg.println(id + "/" + msgInput.getText() + "/" + listIndex);
// 입력 창 클리어
msgInput.setText("");
}
}
/////////////////////////////////////////********** JList에 ListSelectionListener추가하기위해 구현
public void valueChanged(ListSelectionEvent e) {
//JList에 ListSelectionListener의 valueChanged메소드 구현
listIndex = chatList.getAnchorSelectionIndex(); //마지막에 선택된 채팅리스트의 인덱스값을 얻음
}
//////////////////////////////////////////////////////
public void run() {
// 수신 메시지를 처리하는 변수
String msg;
String[] rmsg;
status = true;
while(status) {
try {
// 메시지 수신과 파싱
msg = inMsg.readLine();
rmsg = msg.split("/");
//**********채팅 리스트를 JList에 추가 하기 위한 코딩**********
chatl= new String[rmsg.length-1];
chatl[0] = "모든 채팅"; //채팅리스트의 처음 값은 모든 채팅
for(int i=2 ; i
chatl[i-1] = rmsg[i]; //서버에서 보내주는 모든 id값 채팅리스트에 저장
chatList.setListData(chatl); // JList에 chatl배열로 세팅
///////////////////////////////////////////////////
// JTextArea에 수신된 메시지 추가
msgOut.append(rmsg[0] + ">"+rmsg[1] + "\n");
// 커서를 현재 대화 메시지에 표시
msgOut.setCaretPosition(msgOut.getDocument().getLength());
} catch(IOException e) {
// e.printStackTrace();
status = false;
}
}
System.out.println("[MultiChatClient]" + thread.getName() + "종료됨");
}
public static void main(String[] args) {
MultiChatClient mcc = new MultiChatClient("127.0.0.1");
}
}
id = idInput.getText();
label2.setText("대화명 : " + id);
clayout.show(tab, "logout");
connectServer();
} else if(obj == logoutButton) {
// 로그아웃 메시지 전송
msgOut.setText("");
outMsg.println(id + "/" + "logout");
// 대화 창 클리어
// 로그인 패널로 전환
clayout.show(tab, "login");
outMsg.close();
try {
inMsg.close();
socket.close();
} catch(IOException e) {
e.printStackTrace();
}
status = false;
}
else if(obj == msgInput) {//메세지를 입력할 때
//***************서버로 id, 메시지, 리스트의 인덱스값을 보내줌***************
outMsg.println(id + "/" + msgInput.getText() + "/" + listIndex);
// 입력 창 클리어
msgInput.setText("");
}
}
/////////////////////////////////////////********** JList에 ListSelectionListener추가하기위해 구현
public void valueChanged(ListSelectionEvent e) {
//JList에 ListSelectionListener의 valueChanged메소드 구현
listIndex = chatList.getAnchorSelectionIndex(); //마지막에 선택된 채팅리스트의 인덱스값을 얻음
}
//////////////////////////////////////////////////////
public void run() {
// 수신 메시지를 처리하는 변수
String msg;
String[] rmsg;
status = true;
while(status) {
try {
// 메시지 수신과 파싱
msg = inMsg.readLine();
rmsg = msg.split("/");
//**********채팅 리스트를 JList에 추가 하기 위한 코딩**********
chatl= new String[rmsg.length-1];
chatl[0] = "모든 채팅"; //채팅리스트의 처음 값은 모든 채팅
for(int i=2 ; i
chatList.setListData(chatl); // JList에 chatl배열로 세팅
///////////////////////////////////////////////////
// JTextArea에 수신된 메시지 추가
msgOut.append(rmsg[0] + ">"+rmsg[1] + "\n");
// 커서를 현재 대화 메시지에 표시
msgOut.setCaretPosition(msgOut.getDocument().getLength());
} catch(IOException e) {
// e.printStackTrace();
status = false;
}
}
System.out.println("[MultiChatClient]" + thread.getName() + "종료됨");
}
public static void main(String[] args) {
MultiChatClient mcc = new MultiChatClient("127.0.0.1");
}
}
소개글