Membuat Aplikasi Client Server Chating Menggunakan Java

Program ini dibuat menggunakan NetBeans IDE 6.9, terdiri dari 5 packages. Sekarang saya akan membuat packages yang pertama dengan nama “Chat” (tanpa tanda kutip). Di dalam packages Chat terdapat 2 class java, yaitu ChatDisplay.java dan ChatRoom.java
Sekarang kita buat dulu class ChatDisplay.java
=====================================
package Chat;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
public class ChatDisplay extends JPanel {
private JTextArea chat;
public ChatDisplay() {
setLayout(new BorderLayout());
chat=new JTextArea();
chat.setEditable(false);
chat.setLineWrap(true);
chat.setWrapStyleWord(true);
add(new JScrollPane(chat));
}
public synchronized void updateChat(String msg) {
chat.append(“\n” + msg);
chat.setCaretPosition(chat.getText().length());
}
}
=========================================
Setelah itu kita buat class ChatRoom.java
=========================================
package Chat;
import User.UserDisplay;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
public class ChatRoom extends JFrame {
private ChatDisplay chatDisplay;
protected UserDisplay userDisplay;
public ChatRoom() {
super(“by jogjavasia.com”);
chatDisplay=new ChatDisplay();
userDisplay=new UserDisplay();
JSplitPane splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
splitPane.setLeftComponent(userDisplay);
splitPane.setRightComponent(chatDisplay);
splitPane.setDividerSize(3);
add(splitPane);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void updateChat(String msg) {
chatDisplay.updateChat(msg);
}
public void setUserList(String userlist) {
userDisplay.setUserList(userlist);
}
}