Commit 8cf41efc authored by 9731073's avatar 9731073

first commit

parent 6e9d0d40
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);
addMessage("abtin","safhudas");
setVisible(true);
}
public void addMessage(String userName,String message){
String sb_1=userName+ ":"+message;
append(sb_1);
}
}
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
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 ArrayList<String> users=new ArrayList<>();
public ChatRoomGUI(ParticipantsArea participantsArea){
super();
this.setTitle(WINDOWS_TITLE);
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
participantsArea=new ParticipantsArea();
this.add(participantsArea,BorderLayout.WEST);
participantsArea.addPart("Abtin");
participantsArea.removePart("Abtin");
ChatArea chatBox = new ChatArea();
this.add(new JScrollPane(chatBox), BorderLayout.CENTER);
MessageArea messageArea=new MessageArea();
this.add(messageArea,BorderLayout.SOUTH);
this.setVisible(true);
}
}
public class Main {
public static void main(String[] args) {
ParticipantsArea participantsArea=new ParticipantsArea();
ChatRoomGUI chatRoomGUI=new ChatRoomGUI(participantsArea);
UserNameFrame userNameFrame=new UserNameFrame();
}
}
import javax.swing.*;
import java.awt.*;
public class MessageArea<BTN_TXT> extends JPanel {
private static final String BTN_TXT="Send Message";
JTextField textField;
JButton btn;
public MessageArea()throws HeadlessException{
super();
this.setLayout(new BorderLayout());
textField=new JTextField();
add(textField,BorderLayout.CENTER);
btn=new JButton(BTN_TXT);
add(btn,BorderLayout.EAST);
setVisible(true);
}
public void setTextField(String textField){
this.textField.setText(textField);
}
public JButton getBtn(){
return btn;
}
public JTextField getTextField(){
return textField;
}
}
import javax.swing.*;
import java.awt.*;
public class ParticipantsArea extends JPanel {
private static final String LABEL_TXT="people:";
private static int count=0;
DefaultListModel model=new DefaultListModel();
public ParticipantsArea(){
super();
this.setLayout(new BorderLayout());
JLabel label=new JLabel(LABEL_TXT);
JList list=new JList(model);
add(label,BorderLayout.NORTH);
add(list,BorderLayout.CENTER);
setVisible(true);
}
public void addPart(String user){
model.add(count,user);
count++;
}
public void removePart(String user){
model.removeElement(user);
}
}
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_TXT);
add(btn, BorderLayout.PAGE_END);
setSize(WIDTH, HEIGHT);
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