Commit 029ba397 authored by 9731044's avatar 9731044

initial commit

parents
Pipeline #638 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LAB10</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
File added
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class ChatArea extends JTextArea {
private static final int ROWS = 10, COLUMNS = 30;
private String name;
private String text;
public ChatArea() {
super(ROWS, COLUMNS);
this.setEditable(false);
this.setLineWrap(true);
this.setVisible(true);
}
public void addMessage(String name, String text) {
setText(name + "\n "+text);
}
}
import java.awt.BorderLayout;
import javax.swing.*;
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 UsernameFrame username = new UsernameFrame();
private ChatArea chatBox;
private MessageArea msg;
private ParticipantArea participant;
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);
this.setVisible(true);
chatBox = new ChatArea();
this.add(new JScrollPane(chatBox), BorderLayout.CENTER);
msg = new MessageArea();
this.add(new JScrollPane(msg), BorderLayout.PAGE_END);
participant = new ParticipantArea();
this.add(new JScrollPane(participant), BorderLayout.WEST);
}
public void addNewMessage(String name , String text) {
chatBox.addMessage(name, text);
}
public void addNewParticipant(String name) {
participant.addOnlinePerson(name);
}
public void removeParticipant(String name) {
participant.removeOnlinePerson(name);
}
}
\ No newline at end of file
public class Main {
public static void main(String[] args) {
ChatRoomGUI chatRoom = new ChatRoomGUI();
UsernameFrame username = new UsernameFrame();
chatRoom.addNewMessage("User 0", "Hello");
for(int i=0 ;i<10;i++) {
chatRoom.addNewParticipant("User "+ i);
}
chatRoom.removeParticipant("User 1");
}
}
import java.awt.BorderLayout;
import java.awt.Label;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MessageArea extends JPanel{
JTextField t;
JButton b;
public final static String TEXT = "send message:";
public MessageArea() {
this.setLayout(new BorderLayout());
t = new JTextField();
this.add(t,BorderLayout.CENTER);
b = new JButton(TEXT);
add(b, BorderLayout.EAST);
this.setVisible(true);
}
}
import java.awt.BorderLayout;
import java.awt.Label;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
public class ParticipantArea extends JPanel{
DefaultListModel<String> onlinelist;
public final static String TEXT = "online people:";
public ParticipantArea() {
super();
this.setLayout(new BorderLayout());
Label l1 = new Label(TEXT);
this.add(l1,BorderLayout.PAGE_START );
onlinelist = new DefaultListModel<>();
JList <String> list = new JList<>(onlinelist);
list.setSize(50,50);
this.add(list, BorderLayout.WEST);
this.setVisible(true);
}
public void addOnlinePerson(String username) {
onlinelist.addElement(username);
}
public void removeOnlinePerson(String username) {
onlinelist.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_TEXT = " 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_TEXT);
add(label, BorderLayout.PAGE_START);
textField = new JTextField();
add(textField, BorderLayout.CENTER);
btn = new JButton(LABEL_TEXT);
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