2012-01-06 38 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; 
    } 

我需要紅色的錯誤。此消息(「錯誤!」)發送給用戶,他寫了類似於/ 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; 
} 

在服務器:

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); 
      } 
     } 
    } 

我已編輯的一些名字的(使用挪威),所以這可能是一個問題的U,但該計劃的作品。唯一的問題是,我不能得到錯誤信息的紅色

編輯2:忘記在客戶端GUI:

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 2012-01-06 13:53:42

+1

向我們展示樣式(顏色)界面的代碼,也許我們可以提供幫助。你在使用Swing,AWT,SWT,一個終端窗口嗎? – jefflunt 2012-01-06 14:38:50

回答

0

如果您使用的是控制檯窗口中,你必須找到功能特定於您的操作系統來設置文本顏色。這些功能因操作系統而異,因此,請使用控制檯窗口重新考慮問題,或針對計劃使用應用程序的每個系統解決問題。如果您使用的是類似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 2012-01-08 14:58:41

+0

確保您有一個可用於編寫的圖形對象'g'。我不知道您是否可以在不設計或使用第三方庫的情況下設置特定文本的顏色。 – collinjsimpson 2012-01-08 20:14:33