Commit 931535cc authored by Amirhosein Rajabpour's avatar Amirhosein Rajabpour

second commit

parent f0005cc9
Pipeline #633 failed with stages
...@@ -23,9 +23,16 @@ public class ChatRoomGUI extends JFrame{ ...@@ -23,9 +23,16 @@ public class ChatRoomGUI extends JFrame{
this.add(messagebox,BorderLayout.PAGE_END); this.add(messagebox,BorderLayout.PAGE_END);
ParticipantsArea participantsArea = new ParticipantsArea(); ParticipantsArea participantsArea = new ParticipantsArea();
this.add(participantsArea,BorderLayout.WEST); this.add(new JScrollPane(participantsArea),BorderLayout.WEST);
participantsArea.addNewParticipant("akbar");
participantsArea.removeParticipant("akbar");
participantsArea.addNewParticipant("ali");
participantsArea.addNewParticipant("asghar");
this.setVisible(true); this.setVisible(true);
} }
} }
\ No newline at end of file
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.ArrayList;
import javax.swing.JList; import javax.swing.JList;
public class ParticipantsArea extends JPanel { public class ParticipantsArea extends JPanel {
DefaultListModel model;
JList userslist;
public ParticipantsArea(){ public ParticipantsArea(){
super();
JLabel label = new JLabel("online users"); JLabel label = new JLabel("online users");
add(label, BorderLayout.NORTH); add(label, BorderLayout.PAGE_START);
this.setLayout(new GridLayout(10,1));
model = new DefaultListModel();
userslist = new JList(model);
this.add(userslist,BorderLayout.CENTER);
} }
DefaultListModel model = new DefaultListModel();
JList userslist = new JList(model);
public void addNewParticipant(String userName){ public void addNewParticipant(String userName){
if(!model.contains(userName)) if(!model.contains(userName))
model.addElement(userName); model.addElement(userName);
// System.out.println(model);
} }
public void removeParticipant(String userName){ public void removeParticipant(String userName){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment