I’ve now made a JList which is based on an arraylist, and is being filled by the defaultlistmodel. The list will add people when they connect to the server, but it will not show the one connecting, or the ones connecting after. So, i have to update the JList.
My question is:
What should i be updating? Is it possible to use a timer which runs the update, or should i implement an updatemethod which runs when someone enters the server?
ps. This is an chatserver, much like IRC.
Here is some of the code:
The GUI:
jList2 = new javax.swing.JList();
try{
jList2.setModel(gl.getUsersOnlineAsDefaultListModel(gl.getClients())
);
}catch(RemoteException ex){
System.out.println(ex);
}
jScrollPane3.setViewportView(jList2);
The GUI Logic:
public DefaultListModel getUsersOnlineAsDefaultListModel(ArrayList<Client> clients) throws RemoteException {
DefaultListModel result = new DefaultListModel();
for(Client c : clients){
result.addElement(c.findName());
}
return result;
}
public ArrayList<Client> getClients() throws RemoteException, NullPointerException{
return cf.getClients();
}
The serverside:
ArrayList clients = new ArrayList<Client>();
public ArrayList<Client> getClients(){
return clients;
}
I think the best way to do that is implementing a listener fired by the event the client enters the server which updates the JList.