I'm trying to make a chat program, basically like an aim program. One GUI is for the buddy list, and the other is for a chat window. In my buddy list, I can't figure out a way to list other people in the network who are online. I want to use a jList. But if theres another way then that's fine. The list must also update it self when some signs on and signs off. Can anyone help??? heres what i have so far. Its the GUI plus a little networking.
Code:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* CSChat_COMMENT
*
* @author bmm7867: Bryan Minicucci
*/
public class CSChat extends Thread{
public static String screenName;
private static NetworkChatServer server;
private Set buddies;
/**
* creates frame
*
*/
public CSChat(String name) {
super("Chat Program");
//Frames and Labels
JFrame buddyList = new JFrame("Chat Program");
buddyList.setDefaultCloseOperation(buddyList.EXIT_ON_CLOSE);
buddyList.setLayout(new BorderLayout());
buddyList.setBackground(Color.LIGHT_GRAY);
JLabel welcome = new JLabel("Welcome " + name);
JLabel users = new JLabel("Users Online:");
JList list = new JList();
list.setBorder(BorderFactory.createLineBorder(Color.black,2));
screenName = name;
JMenuBar mb = new JMenuBar();
buddyList.setJMenuBar(mb);
JMenu fileMenu = new JMenu("File");
mb.add(fileMenu);
JMenu helpMenu = new JMenu("Help");
mb.add(helpMenu);
JMenuItem mQuit = new JMenuItem("Quit");
fileMenu.add(mQuit);
JMenuItem mPrint = new JMenuItem("Print Help");
helpMenu.add(mPrint);
//Adding to frame
buddyList.getContentPane().add((welcome), BorderLayout.NORTH);
buddyList.getContentPane().add((users), BorderLayout.WEST);
buddyList.getContentPane().add((list), BorderLayout.CENTER);
buddyList.setSize(400,400);
buddyList.setVisible(true);
//Chat Window
JFrame chat = new JFrame("Chat with User");
chat.setSize(400,400);
chat.setBackground(Color.LIGHT_GRAY);
chat.getContentPane().setLayout(new GridLayout(3,1));
JLabel chatBox = new JLabel();
JTextArea text = new JTextArea();
JButton submit = new JButton("Submit");
JMenuBar cb = new JMenuBar();
chat.setJMenuBar(cb);
JMenu fileMenu2 = new JMenu("File");
cb.add(fileMenu2);
JMenu editMenu2 = new JMenu("Edit");
cb.add(editMenu2);
JMenu helpMenu2 = new JMenu("Help");
cb.add(helpMenu2);
JMenuItem mQuit2 = new JMenuItem("Exit");
fileMenu2.add(mQuit2);
JMenuItem mFont2 = new JMenuItem("Font");
editMenu2.add(mFont2);
JMenuItem mPrint2 = new JMenuItem("Print Help");
helpMenu2.add(mPrint2);
chat.getContentPane().add(chatBox);
chat.getContentPane().add(text);
chat.getContentPane().add(submit);
// chat.setVisible(true);
}
/**
* main method
*
* @param args command line arguments
*/
public static void main( String args[] ) {
String myHandle = null;
//Setting up Server
try {
myHandle = args[0];
server = new NetworkChatServer();
server.setEnabled(true);
server.register(myHandle);
}catch (Exception e) {
System.err.println("" + myHandle + " is already in use");
}
CSChat c = new CSChat(myHandle);
}
/**
* an Action Listener that is activated when someone requests a chat
*
*/
// public void actionPerformed(ActionEvent e);
// server.addChatListener((ChatListener listen){
// public void registeredUsers(Set users){
// buddies = users;
// }
} // CSChat
the bottom in the comment blocks was a way i was trying to create a chat listener but i couldnt get it to compile. I tried a bunch of variations