Commit e95432a3 authored by 9731050's avatar 9731050

first

parent 908b5d52
Pipeline #644 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_11" default="true" 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$/lab10.iml" filepath="$PROJECT_DIR$/lab10.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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
package chatRoom;
import javax.swing.*;
public class ChatArea extends JTextArea {
private static final int ROWS = 10, COLUMNS = 30;
public ChatArea() {
super(ROWS, HEIGHT);
this.setEditable(false);
this.setLineWrap(true);
}
public void addMessage(String username, String message) {
this.setText(this.getText() + username + ":\n" + message + "\n");
}
}
package chatRoom;
import javax.swing.*;
import java.awt.*;
public class ChatRoomGUI extends JFrame {
private static String WINDOWS_TITLE = "AUT Chat Room";
private final int WIDTH = 500, HEIGHT = 500;
private final int X = 100, Y = 100;
private ChatArea chatBox;
private MessageArea messageArea;
private ParticipantsArea participantsArea;
public ChatRoomGUI() throws HeadlessException {
super();
this.setTitle(WINDOWS_TITLE);
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
chatBox = new ChatArea();
this.add(new JScrollPane(chatBox), BorderLayout.CENTER);
messageArea = new MessageArea();
this.add(messageArea, BorderLayout.SOUTH);
participantsArea = new ParticipantsArea();
this.add(participantsArea, BorderLayout.WEST);
this.setVisible(true);
}
public void addNewMessage(String username, String message) {
chatBox.addMessage(username, message);
}
public void addNewParticipant(String username) {
participantsArea.addParticipant(username);
}
public void removeParticipant(String username) {
participantsArea.removeParticipant(username);
}
}
package chatRoom;
import chatRoom.ChatRoomGUI;
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main (String[] args) {
ChatRoomGUI chat=new ChatRoomGUI();
chat.addNewParticipant("ali");
chat.addNewParticipant("mohammad");
chat.removeParticipant("ali");
}
}
package chatRoom;
import javax.swing.*;
import java.awt.*;
public class MessageArea extends JPanel {
public MessageArea() {
super(new BorderLayout());
JButton send = new JButton("Send");
this.add(send, BorderLayout.EAST);
JTextField text = new JTextField();
text.setBackground(Color.green);
this.add(text, BorderLayout.CENTER);
}
}
package chatRoom;
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);
}
}
package chatRoom;
import javax.swing.*;
import java.util.ArrayList;
public class ParticipantsArea extends JList<String> {
private ArrayList<String> participants = new ArrayList<>();
public ParticipantsArea() {
super();
this.setListData(participants.toArray(new String[participants.size()]));
this.setVisible(true);
}
public void addParticipant(String username) {
participants.add(username);
this.setListData(participants.toArray(new String[participants.size()]));
}
public void removeParticipant(String username) {
participants.remove(username);
this.setListData(participants.toArray(new String[participants.size()]));
}
}
package chatRoom;
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(LABEL_TXT);
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
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