2012-01-06 4 views
-2
public String commando(String username, String channel, String text) throws RemoteException{ 
     String[] result = text.split(" ", 3); 
     if(result[0].equalsIgnoreCase("/join")){ 
      channel = result[1]; 
      setChannel(channel); 
      joinChannel(username, channel); 
     } 
     else if(result[0].equalsIgnoreCase("/leave")){ 
      channel = result[1]; 
      setChannel(channel); 
      leaveChannel(username, channel); 
     } 
     else if(result[0].equalsIgnoreCase("/whisper")){ 
      for (int x=2; x<result.length; x++) 
      newPrivateMessage(username, result[1], result[x]); 
     } 
     else if(result[0].equalsIgnoreCase("/exit")){ 
      System.exit(0); 
     } 
     else{ 
     error(brukernavn, "Wrong!"); 
     } 

     return tekst; 
    } 

빨간색으로 표시하려면 오류가 필요합니다. 이 메시지 ("Wrong!")는/dfdsfsd와 같은 것을 작성한 사용자에게 전달됩니다. 화면에 메시지가 표시되지만 빨간색으로 표시되지 않습니다. 어떤 생각?RMI 채팅 프로그램에 빨간색 "오류"메시지가 필요합니다.

편집 :

간섭 : 서버에서

public interface ChatFront extends Remote { 
     void error(String to, String message) throws RemoteException; 
} 

public interface Klient extends Remote { 
     void error(String to, String message) throws RemoteException; 
} 

: 나는 (노르웨이어를 사용) 그래서 이것은 U에 대한 문제가 될 수있는 이름 중 일부를 편집 한

class ChatFrontImpl extends UnicastRemoteObject implements ChatFront { 

    private UserDAO b = new UserDAO(); 
    private Hashtable<String, ArrayList<String>> chanel = new Hashtable<String, ArrayList<String>>(); 
    private ArrayList<Klient> clients= new ArrayList<Client>(); 


    public ChatFrontImpl() throws RemoteException { 
    } 
public void error(String to, String message) throws RemoteException{ 
     errorTo(to, message); 
    } 
private void errorTo(String to, String message) throws RemoteException{ 
     for(Client k: clients){ 
      if(k.findName().equals(to)){ 
       k.error(to, message); 
      } 
     } 
    } 

, 그러나 프로그램은 작동합니다. 이 기능을 찾기 위해, 당신이해야 콘솔 창을 사용하는 경우

public class GUI extends javax.swing.JFrame { 

    GUILogikk gl = new GUILogikk(this); 

    public void error(String to, String message){ 
     //chatFelt.setCaretColor(Color.RED); 
     chatFelt.append("" + message + "\n"); 
     chatFelt.setCaretPosition(chatFelt.getText().length()); 
    } 
} 
+0

사용자 인터페이스 기술은 무엇입니까? – home

+1

인터페이스에 스타일 (색상)을 지정하는 코드를 보여 주면 도움이 될 수 있습니다. Swing, AWT, SWT, 터미널 창을 사용하고 있습니까? – jefflunt

답변

0

: 클라이언트의 GUI를 잊어 버렸 : 유일한 문제는 내가 오류 메시지에

편집이 붉은 색을 얻을 질수 있다는 것입니다 운영 체제에 따라 텍스트 색상을 설정할 수 있습니다. 이러한 기능은 운영 체제에 따라 다르므로 콘솔 창을 사용하여 재검토하거나 응용 프로그램을 사용할 각 시스템의 문제를 해결하십시오. Swing과 같은 것을 사용하는 경우, 그리려는 구성 요소와 관련된 텍스트 색상 속성 (setSelectedTextColor() 등)을 검사 할 수 있습니다. 자세한 내용은 여기 : 당신은 단순히 그래픽 객체를 그리려는 경우 JTextArea

는 다음을 수행 할 수 있습니다

g.setColor(Color.RED); 
g.drawString("WRONG!", 32, 32); // text, x, y 
+0

메시지를 쓰는 GUI에서 이와 비슷한 작업을하려고하는데 g.setColor (Color.RED); setColor에서 심볼을 찾을 수 없습니다. 도노, 어떻게 해야할지. 나는 그녀가 내가 변화를해야한다고 생각한다. public void feilmelding (String til, String melding) { //chatFelt.setColor(Color.RED); chatFelt.append (melding + "\ n"); chatFelt.setCaretPosition (chatFelt.getText(). length()); } – user1134414

+0

쓰기 가능한 그래픽 객체 'g'가 있어야합니다. 제 3 자 라이브러리를 디자인하거나 사용하지 않고도 특정 텍스트의 색상을 설정할 수 있는지 여부는 알 수 없습니다. – collinjsimpson

관련 문제