Commit 6e4d319e authored by Roham's avatar Roham

VERY EVIL INDEED

parent 25fc1e8c
import javax.swing.*;
public class ChatArea extends JTextArea {
private static final int ROWS = 10, COLUMNS = 30;
public ChatArea() {
super(ROWS, COLUMNS);
this.setEditable(false);
this.setLineWrap(true);
this.setVisible(true);
}
public void addMessage(String name, String message)
{
this.append(name + " : " + message + "\n");
}
}
\ No newline at end of file
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;
ChatArea chatArea;
MessageArea messageArea;
ParticipantsArea participantsArea;
public ChatRoomGUI() {
super();
this.setLayout(new BorderLayout());
this.setTitle(WINDOWS_TITLE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
chatArea = new ChatArea();
this.add(new JScrollPane(chatArea), BorderLayout.CENTER);
messageArea = new MessageArea();
this.add(messageArea, BorderLayout.PAGE_END);
participantsArea = new ParticipantsArea();
this.add(new JScrollPane(participantsArea), BorderLayout.WEST);
this.setVisible(true);
}
public void addNewMessage(String name, String message)
{
this.chatArea.addMessage(name, message);
}
public void addNewParticipant(String name)
{
this.participantsArea.addNewParticipant(name);
}
public void removeNewParticipant(String name)
{
this.participantsArea.removeParticipant(name);
}
}
\ No newline at end of file
public class Main {
public static void main(String[] args) {
ChatRoomGUI chatRoomGUI = new ChatRoomGUI();
NameFrame nameFrame = new NameFrame();
chatRoomGUI.addNewParticipant("ROHAM");
chatRoomGUI.addNewMessage("ROHAM", "SALAM");
chatRoomGUI.addNewParticipant("AMIRHOSSEIN");
chatRoomGUI.addNewMessage("AMIRHOSSEIN", "SALAM");
chatRoomGUI.addNewParticipant("GHOLI");
chatRoomGUI.removeNewParticipant("GHOLI");
}
}
import javax.swing.*;
import java.awt.*;
public class MessageArea extends JPanel{
JTextField textField;
JButton btn;
public MessageArea() throws HeadlessException {
super();
this.setLayout(new BorderLayout());
textField = new JTextField();
textField.setEditable(true);
add(textField, BorderLayout.CENTER);
btn = new JButton("SEND");
add(btn, BorderLayout.EAST);
setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
public class NameFrame 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 NameFrame() 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_TXT);
add(btn, BorderLayout.PAGE_END);
setSize(WIDTH, HEIGHT);
setVisible(true);
}
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ParticipantsArea extends JPanel {
private final int ROW = 20, COLUMN = 1;
DefaultListModel<String> model;
JList<String> list;
public ParticipantsArea() throws HeadlessException {
super();
GridLayout g = new GridLayout(20, 1);
this.setLayout(g);
JLabel label = new JLabel("Online Users");
this.add(label);
this.model= new DefaultListModel();
this.list = new JList(model);
this.add(list);
this.setVisible(true);
}
public void addNewParticipant(String name)
{
if (!this.model.contains(name)) {
this.model.addElement(name);
}
}
public void removeParticipant(String name)
{
if (this.model.contains(name)) {
this.model.removeElement(name);
}
}
}
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