Commit d8dbfb2e authored by amsen's avatar amsen

init commit

parents
Pipeline #692 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" default="true" project-jdk-name="9" 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$/ServerSide.iml" filepath="$PROJECT_DIR$/ServerSide.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="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<?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 java.io.*;
import java.net.Socket;
import java.util.Scanner;
public class ClientHandler implements Runnable{
public Socket socket;
public PrintWriter dataOutputStream;
public Scanner dataInputStream;
public Server myServer;
public ClientHandler(Socket client, Server myServer) throws Exception {
System.out.println("building client handler!");
if (client == null)
throw new Exception("client can't be null");
this.socket = client;
this.myServer = myServer;
dataOutputStream = new PrintWriter(client.getOutputStream(), true);
dataInputStream = new Scanner(client.getInputStream());
//run();
}
private void handleIncomingMessages(String message){
System.out.println(message);
for(ClientHandler clientHandler : myServer.clients){
clientHandler.dataOutputStream.println(message);
}
}
@Override
public void run() {
System.out.println("wating");
while(true){
try {
String input = dataInputStream.nextLine();
if(input == ":wq")
break;
handleIncomingMessages(input);
//System.exit(0);
} catch (Exception e) {
//return;
e.printStackTrace();
}
}
}
}
\ No newline at end of file
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
public class Server {
private static final int PORT = 4321;
private ServerSocket serverSocket;
ArrayList<ClientHandler> clients;
public Server() throws IOException {
clients = new ArrayList<>();
serverSocket = new ServerSocket(PORT);
while (true) {
Socket client = serverSocket.accept();
try {
ClientHandler cur = new ClientHandler(client, this);
clients.add(cur);
Thread thread = new Thread(cur);
thread.start();
System.out.println(thread.getState());
} catch (Exception e){
e.printStackTrace();
}
}
}
public static void main(String args[]){
try {
System.out.println("start to");
Server server = new Server();
} catch (Exception e){
System.out.println("couldn't");
//
}
}
}
\ No newline at end of file
<component name="libraryTable">
<library name="gson-2.2.2">
<CLASSES>
<root url="jar://$USER_HOME$/Downloads/gson-2.2.2.jar/gson-2.2.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" default="true" project-jdk-name="9" 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$/lab11.iml" filepath="$PROJECT_DIR$/lab11.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<?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" />
<orderEntry type="library" name="gson-2.2.2" level="project" />
</component>
</module>
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ChatArea extends JTextArea{
private static final int COL = 30, ROW = 10;
private String text;
public ChatArea() {
super(ROW, COL);
text = "";
this.setEditable(false);
this.setLineWrap(true);
}
public void addText(String sender, String message){
text = text + (text.equals("") ? "" : "\n") + sender + ": " + message;
this.setText(text);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
ChatArea chatArea = new ChatArea();
chatArea.addText("ali", "salam!!!!!");
chatArea.addText("amsen", "siloom!!!!!");
chatArea.addText("sadegh", "wooow!!!!!");
chatArea.addText("amsen","iln");
frame.add(chatArea);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
public class ChatGUI extends JFrame {
private EnterActionListener enterActionListener = null;
public NetWork netWork;
public OnlineList onlineList = new OnlineList();
public ChatArea chatArea = new ChatArea();
public TypeArea typeArea = new TypeArea(this);
public String me;
public void addEnterActionListener(EnterActionListener enterActionListener){
this.enterActionListener = enterActionListener;
}
public void loggedin(String s){
onlineList.addPerson(s);
me = s;
}
public ChatGUI(){
super();
setLayout(new BorderLayout());
add(onlineList, BorderLayout.WEST);
add(chatArea, BorderLayout.CENTER);
add(typeArea, BorderLayout.SOUTH);
setSize(500, 500);
netWork = new NetWork(this);
Thread thread = new Thread(netWork);
thread.start();
}
}
public interface EnterActionListener {
void newLogin(String username);
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoginPage extends JFrame{
private final String WINDOWS_TITLE = "Login page";
private final int WIDTH = 500, HEIGHT = 200;
private final int X = 100, Y = 100;
private JTextField usernamet;
private JButton loginb;
private JLabel usernamel;
public LoginPage(ChatGUI next){
super();
this.setTitle(WINDOWS_TITLE);
this.setLayout(new GridLayout(3, 1));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
usernamel = new JLabel();
usernamel.setText("username");
usernamet = new JTextField();
usernamel = new JLabel();
usernamel.setText("username");
loginb = new JButton();
loginb.setText("login");
add(usernamel);
add(usernamet);
add(loginb);
loginb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
next.setVisible(true);
next.loggedin(usernamet.getText());
LoginPage.super.setVisible(false);
}
});
this.setVisible(true);
}
/*public static void main(String[] args){
LoginPage tmp = new LoginPage();
}*/
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class Main {
public static void main(String[] args){
ChatGUI chatGUI = new ChatGUI();
LoginPage loginPage = new LoginPage(chatGUI);
while(true);
//frame.setVisible(true);
}
}
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class NetWork implements Runnable{
private ChatGUI myGUI;
private Socket socket;
private PrintWriter dataOutputStream;
private Scanner dataInputStream;
public NetWork(ChatGUI myGUI) {
this.myGUI = myGUI;
try {
socket = new Socket("127.0.0.1", 4321);
dataOutputStream = new PrintWriter(socket.getOutputStream(), true);
dataInputStream = new Scanner(socket.getInputStream());
} catch (Exception e) {
//
}
}
public void close(){
try {
socket.close();
} catch (Exception e){
//
}
}
public void send(String s) {
try {
dataOutputStream.println(s);
System.out.println(s + "sent!!!");
} catch (Exception e) {
//
}
}
public void run(){
while(true){
try {
String input = dataInputStream.nextLine();
myGUI.chatArea.addText("other", input);
//System.exit(0);
} catch (Exception e) {
//return;
e.printStackTrace();
}
}
}
/*public static void main(String args[]) {
NetWork netWork = new NetWork();
Gson gson = new Gson();
netWork.send(gson.fromJson("\"message\"", String.class));
netWork.send(gson.fromJson("\":wq\"", String.class));
//while(true);
netWork.close();
}*/
}
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class OnlineList extends JPanel{
private JLabel label;
private ArrayList<JLabel> onlinePersons;
public OnlineList(){
super();
onlinePersons = new ArrayList<>();
this.setLayout(new GridLayout(20, 1));
label = new JLabel("online persons");
label.setOpaque(true);
label.setBackground(Color.ORANGE);
label.setForeground(Color.WHITE);
add(label);
}
public void addPerson(String s){
onlinePersons.add(new JLabel(s));
add(onlinePersons.get(onlinePersons.size()-1));
}
public void removePerson(String s){
for(int i=0 ; i<onlinePersons.size() ; i++)
if(onlinePersons.get(i).getText().equals(s)){
onlinePersons.remove(i);
remove(i+1);
break;
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
OnlineList onlineList = new OnlineList();
onlineList.addPerson("hasan");
onlineList.addPerson("nilo");
onlineList.addPerson("salam");
onlineList.removePerson("nilo");
onlineList.removePerson("salam");
frame.add(onlineList);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TypeArea extends JPanel{
private JTextField message;
private JButton send;
private ChatGUI chatGUI;
public TypeArea(ChatGUI chatGUI){
super();
this.chatGUI = chatGUI;
this.setLayout(new GridLayout(1, 2));
message = new JTextField("type your message here");
send = new JButton("send!");
add(message);
add(send);
send.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
chatGUI.netWork.send(message.getText());
}
});
}
/*public static void main(String[] args) {
JFrame frame = new JFrame();
TypeArea typeArea = new TypeArea(this);
frame.add(typeArea);
frame.setSize(500, 500);
frame.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