Java RMI聊天程序,需要红色“;“错误”;消息

Java RMI聊天程序,需要红色“;“错误”;消息,java,colors,chat,Java,Colors,Chat,在服务器中: 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; } 如果您使用的是控制台

在服务器中:

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

如果您使用的是控制台窗口,则必须找到特定于操作系统的函数来设置文本颜色。这些功能因操作系统而异,因此请重新考虑使用控制台窗口,或者针对您计划在其上使用应用程序的每个系统解决此问题。如果您使用的是Swing之类的工具,则可以检查与您试图绘制的组件相关联的可用文本颜色属性(setSelectedTextColor(),等等)。详情如下:

如果只想在图形对象上绘制,可以执行以下操作:

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

什么是用户界面技术?向我们展示为您的界面设计样式(颜色)的代码,也许我们可以提供帮助。您是否使用Swing、AWT、SWT、终端窗口?我试图在编写消息的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());}请确保有图形对象“g”可供写入。我不知道您是否可以在不设计或使用第三方库的情况下设置特定文本的颜色。
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());
    }
}
g.setColor(Color.RED);
g.drawString("WRONG!", 32, 32); // text, x, y