rendered paste bodypublic class Chatbox {
private Applet applet;
private Rectangle cb;
private Chat chat[] = new Chat[4];
public int count;
private Chat msg = new Chat(14);
private Player player;
public boolean needsUpdate = true;
public Chatbox(Applet a, Player p) {
applet = a;
player = p;
for (int i = 0; i < chat.length; i++) {
chat[i] = new Chat();
}
needsUpdate = true;
}
public void update() {
}
public void paint(Graphics g) {
if(needsUpdate){
g.setColor(Color.blue);
g.fillRect(0, 400, 500, 265);
for (int i = 0; i < chat.length; i++) {
g.setColor(chat[i].color);
g.setFont(new Font(chat[i].font, chat[i].type, chat[i].size));
g.drawString(chat[i].text, 0, 415 + (20 * i));
g.drawLine(0, 480, 500, 480);
}
g.setColor(msg.color);
g.setFont(new Font(msg.font, msg.type, msg.size));
g.drawString(player.name + ": " + msg.text, 0, 495);
needsUpdate = false;
}
}
public void setChat(String text) {
chat[0] = chat[1];
chat[1] = chat[2];
chat[2] = chat[3];
chat[3] = null;
chat[3] = new Chat();
chat[3].text = text;
needsUpdate = true;
System.out.println(text);
}
public void setChat(String text, String font, int type, int size, Color color) {
}
public void drawString(char c) {
if (c == '\b') {
if (msg.text.length() > 0)
msg.text = msg.text.substring(0, msg.text.length() - 1);
needsUpdate = true;
return;
}
if (c == '\n') {
setChat(player.name + ": " + msg.text);
msg.text = "";
}
if (msg.text.length() <= 50)
msg.text = msg.text + c;
needsUpdate = true;
}
}