Commit 10343f6e authored by 9731001's avatar 9731001

lab10

parents
Pipeline #636 failed with stages
package com.company;
import javax.swing.*;
public class ChatArea extends JTextArea {
private static final int ROWS = 10, COLUMNS = 30;
private String showingMessage;
DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
public ChatArea() {
super(ROWS, COLUMNS);
this.setEditable(false);
this.setLineWrap(true);
showingMessage = new String("");
}
public void Show (){
this.append(showingMessage);
this.setEditable(false);
}
public void addMessage (String username , String message){
showingMessage += username + " :\n" + message + "\n\n";
this.append(showingMessage);
}
}
\ No newline at end of file
package com.company;
import javax.swing.*;
import java.awt.*;
public class ChatRoomGUI extends JFrame{
private final String WINDOWS_TITLE = "AUT Chat Room";
private final int WIDTH = 500, HEIGHT = 500;
private final int X = 100, Y = 100;
private ChatArea chatBox;
private MessageArea messageArea;
private ParticipantsArea participantsArea;
public ChatRoomGUI() {
super();
this.setTitle(WINDOWS_TITLE);
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
chatBox = new ChatArea();
this.add(chatBox, BorderLayout.CENTER);
messageArea = new MessageArea();
messageArea.sendingMassage();
this.add(messageArea , BorderLayout.SOUTH);
participantsArea = new ParticipantsArea();
participantsArea.showOnlines();
this.add(participantsArea , BorderLayout.WEST);
this.setVisible(true);
}
public void addMessage(String userName , String message){
chatBox.addMessage(userName , message);
}
public void addNewParticipant(String userName){
participantsArea.addOnlineUser(userName);
}
public void removeParticipant(String userName){
participantsArea.removeOnlineUser(userName);
}
public ParticipantsArea getParticipantsArea(){
return participantsArea;
}
}
package com.company;
public class Main {
public static void main(String[] args) {
ChatRoomGUI chatRoomGUI = new ChatRoomGUI();
chatRoomGUI.addNewParticipant("Fatemeh");
chatRoomGUI.addNewParticipant("Zahra");
chatRoomGUI.removeParticipant("Fatemeh");
chatRoomGUI.addMessage("Zahra" , "Hi!");
}
}
package com.company;
import javax.swing.*;
import java.awt.*;
public class MessageArea extends JPanel {
public MessageArea(){
this.setLayout(new BorderLayout());
}
public void sendingMassage(){
this.setSize(300 , 50);
JButton bot = new JButton("send message");
this.add(new JScrollPane(bot) , BorderLayout.EAST);
JTextArea textArea = new JTextArea("");
textArea.setEditable(true);
this.add(textArea , BorderLayout.WEST);
this.setVisible(true);
}
}
package com.company;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ParticipantsArea extends JPanel {
DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
public ParticipantsArea(){
this.setLayout(new BorderLayout());
}
public void showOnlines(){
JLabel lable = new JLabel("Online users :");
this.add(lable , BorderLayout.NORTH);
this.add(list , BorderLayout.CENTER);
}
public void addOnlineUser(String userName){
model.addElement(userName);
}
public void removeOnlineUser(String userName){
model.removeElement(userName);
}
}
package com.company;
import javax.swing.*; import java.awt.*;
public class UsernameFrame extends JFrame {
private static final String BTN_TXT = " Start Chatting ...";
private static final String LABEL_TXT = " Choose Your UserName ";
private static final int WIDTH = 300, HEIGHT = 100;
JTextField textField;
JButton btn;
public UsernameFrame() throws HeadlessException {
super();
this.setLayout(new BorderLayout());
JLabel label = new JLabel("Choose Your UserName");
add(label, BorderLayout.PAGE_START);
textField = new JTextField();
add(textField, BorderLayout.CENTER);
btn = new JButton("LABEL_TEXT");
add(btn, BorderLayout.PAGE_END);
setSize(WIDTH, HEIGHT);
setVisible(true);
}
}
\ No newline at end of file
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