Commit f0005cc9 authored by Amirhosein Rajabpour's avatar Amirhosein Rajabpour

first commit

parent 22f24db6
Pipeline #632 canceled with stages
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;
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);
chatArea chatbox = new chatArea();
chatbox.addMessage("amir","hello!");
chatbox.setVisible(true);
this.add(new JScrollPane(chatbox), BorderLayout.CENTER);
MessageArea messagebox = new MessageArea();
this.add(messagebox,BorderLayout.PAGE_END);
ParticipantsArea participantsArea = new ParticipantsArea();
this.add(participantsArea,BorderLayout.WEST);
this.setVisible(true);
}
}
\ No newline at end of file
public class Main {
public static void main(String[] args){
ChatRoomGUI chat1 = new ChatRoomGUI();
UsernameFrame chat2 = new UsernameFrame();
}
}
import javax.swing.*;
import java.awt.*;
public class MessageArea extends JPanel {
JTextField textField;
JButton btn;
public MessageArea(){
super();
this.setLayout(new BorderLayout());
textField = new JTextField();
textField.setEditable(true);
add(textField, BorderLayout.CENTER);
btn = new JButton("send");
add(btn, BorderLayout.EAST);
this.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.JList;
public class ParticipantsArea extends JPanel {
public ParticipantsArea(){
JLabel label = new JLabel("online users");
add(label, BorderLayout.NORTH);
}
DefaultListModel model = new DefaultListModel();
JList userslist = new JList(model);
public void addNewParticipant(String userName){
if(!model.contains(userName))
model.addElement(userName);
}
public void removeParticipant(String userName){
if(model.contains(userName))
model.removeElement(userName);
}
}
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 = 400;
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(BTN_TXT);
add(btn, BorderLayout.PAGE_END);
setSize(WIDTH, HEIGHT);
setVisible(true);
}
}
\ No newline at end of file
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);
setVisible(true);
}
public void addMessage(String name, String pm){
String str = name+ ":" + pm;
append(str);
setVisible(true);
}
}
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