루프에 문제가 있습니다. 내 프로젝트에서 나는 소켓에서 소켓을 통해 의견을 보내고있다. 고객의 마지막 코멘트가 여전히 인쇄되어 있기 때문에 무언가 잘못되었습니다.Client에서 while 루프가 잘못되었습니다.
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
while(true){
out.println(rel.getCommentary());
}
getCommentary는
고객의 루프
in = new Scanner(socket.getInputStream());
while(in.hasNextLine()){
showCommentary(in.nextLine());
}
서버 GUI
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == addComment){
String comment=commentField.getText();
rel.setCommentaryText(comment);
panel4.setBackground(Color.green);
}
클라이언트
private void showCommentary(String text){
showArea.append(text+ "\n");
showArea.setCaretPosition(showArea.getDocument().getLength());
}
의 JTextField에서 현재 코멘트와 방법
관계 클래스
public class Relation{
String relation;
public Relation() {
}
public void setCommentaryText(String relation){
this.relation= relation;
}
public String getCommentary(){
return this.relation;
}
}
입력과 출력을 추가하십시오. – darijan
인쇄를 위해 서버 사이트에서 루프를 사용하는 이유는 무엇입니까? –
내가 내 actionPerformed – Dominik