Commit 80cd90f6 authored by Ali Shakoori's avatar Ali Shakoori

very first and last commit of lab10

parents
Pipeline #625 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/GUI.iml" filepath="$PROJECT_DIR$/GUI.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
public class ChatArea extends JTextArea {
private static final int ROWS = 10 , COLUMN = 30;
public ChatArea(){
super(ROWS , COLUMN);
this.setEditable(false);
this.setLineWrap(true);
setVisible(true);
}
public void addMessage(String userName , String Message){
this.append(userName + " : " + Message + "\n");
}
}
import javax.swing.*;
import javax.swing.border.EtchedBorder;
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 = new ChatArea();
private JPanel users = new JPanel();
private ParticipantArea user = new ParticipantArea();
private MessageArea messageArea = new MessageArea();
private JPanel msgArea = new JPanel();
public ChatRoomGUI(){
super();
this.setTitle(WINDOWS_TITLE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
this.add(new JScrollPane().add(chatBox) ,BorderLayout.CENTER );
chatBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
users.setLayout(new BorderLayout());
users.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
users.add(user.getLabel() , BorderLayout.PAGE_START);
users.add(user.getList() , BorderLayout.CENTER);
this.add(users , BorderLayout.WEST);
msgArea.setLayout(new BorderLayout());
msgArea.add(new JScrollPane().add(messageArea) , BorderLayout.CENTER);
msgArea.add(messageArea.getBtn() , BorderLayout.EAST);
this.add(msgArea , BorderLayout.PAGE_END);
users.setVisible(true);
this.setVisible(true);
}
public void addNewMessage(String name , String message){
chatBox.addMessage(name , message);
}
public void addNewParticipant(String name){
user.addUser(name);
}
public Boolean removeParticipant(String name){
if(user.getListOfUsers().contains(name)){
user.getListOfUsers().removeElement(name);
return true;
}
else{
return false;
}
}
}
public class Main {
public static void main(String[] args) {
ChatRoomGUI chatRoom = new ChatRoomGUI();
chatRoom.addNewParticipant("Milad");
chatRoom.addNewParticipant("Ali");
chatRoom.addNewParticipant("Taghi");
chatRoom.addNewParticipant("Naghi");
chatRoom.addNewMessage("Milad" , "Hello Ali");
chatRoom.addNewMessage("Ali" , "Hello Taghi");
chatRoom.addNewMessage("Taghi" , "Hello Naghi");
chatRoom.addNewMessage("Naghi" , "Bye");
UsernameFrame user = new UsernameFrame();
}
}
import javax.swing.*;
public class MessageArea extends JTextField {
private JButton btn;
private final static String BTN_TXT = "Send";
public MessageArea(){
super();
btn = new JButton(BTN_TXT);
this.setEditable(true);
this.setVisible(true);
}
public JButton getBtn() {
return btn;
}
}
import javax.swing.*;
public class ParticipantArea extends JList {
private final static String LBL_TXT = "Online People: ";
private JLabel label;
private DefaultListModel<String> listOfUsers = new DefaultListModel<>();
private JList<String> list = new JList<>(listOfUsers);
public ParticipantArea(){
label = new JLabel(LBL_TXT);
this.setVisible(true);
}
public JLabel getLabel() {
return label;
}
public JList<String> getList() {
return list;
}
public void addUser(String name){
listOfUsers.addElement(name);
}
public DefaultListModel<String> getListOfUsers() {
return listOfUsers;
}
}
import javax.swing.*;
import java.awt.*;
public class UsernameFrame extends JFrame {
public static final String BTN_TXT = " Start Chatting ...";
public 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