Commit 33bc1ed5 authored by mrsl2000's avatar mrsl2000

my ugly chatromm

parents
Pipeline #695 failed with stages
package gui;
import javax.swing.*;
import java.awt.*;
public class ChatArea extends JTextArea {
private static final int ROWS = 10, COLUMNS = 30;
public ChatArea() {
super(ROWS, COLUMNS);
this.setEditable(false);
this.setLineWrap(true);
}
public void addMessage (String user,String text){
super.append(user + " : ");
super.append(text);
}
}
package gui;
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 chatBox = new ChatArea();
MessageArea messageBox = new MessageArea();
ParticipantsArea participantsbox = new ParticipantsArea();
public ChatRoomGUI() throws HeadlessException {
super();
this.setTitle(WINDOWS_TITLE);
this.setLayout(new BorderLayout());
this.add(new JScrollPane(chatBox), BorderLayout.CENTER);
this.add(new JScrollPane(messageBox), BorderLayout.PAGE_END);
this.add(new JScrollPane(participantsbox), BorderLayout.WEST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
this.setVisible(true);
}
public void addUser(String user){
participantsbox.addUser(user);
}
public void addMessage (String user,String text){
chatBox.addMessage(user,text);
}
public static void main (String args[]){
ChatRoomGUI chatroom = new ChatRoomGUI();
}
}
package gui;
import javax.swing.*;
import java.awt.*;
public class MessageArea extends JPanel{
public MessageArea(){
super();
this.setLayout(new GridLayout(1,2));
JTextField textField = new JTextField();
add(textField);
JButton btn = new JButton("Na Be Intellij");
add(btn);
setVisible(true);
}
}
package gui;
import javax.swing.*;
import java.awt.*;
public class ParticipantsArea extends JPanel{
public DefaultListModel<String> list = new DefaultListModel<>();
public ParticipantsArea(){
super();
this.setLayout(new GridLayout(2,1));
JLabel label = new JLabel("Online User");
add(label);
JList<String> listbox = new JList<>(list);
list.addElement("mamal");
list.addElement("pasha");
list.addElement("hossein");
add(listbox);
setVisible(true);
}
public void addUser (String user){
list.addElement(user);
}
}
package gui;
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("Na Be Intellij");
add(btn, BorderLayout.PAGE_END);
setSize(WIDTH, HEIGHT);
setVisible(true);
}
public static void main(String args []){
UsernameFrame user = new UsernameFrame();
}
}
\ 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