Démarrage codage chat
This commit is contained in:
parent
ce473a3aa6
commit
80ca7168c3
11 changed files with 154 additions and 0 deletions
10
chat/.classpath
Normal file
10
chat/.classpath
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?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-13">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
17
chat/.project
Normal file
17
chat/.project
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>chat</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>
|
14
chat/.settings/org.eclipse.jdt.core.prefs
Normal file
14
chat/.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=13
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=13
|
||||||
|
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.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=13
|
BIN
chat/bin/model/Contact.class
Normal file
BIN
chat/bin/model/Contact.class
Normal file
Binary file not shown.
BIN
chat/bin/model/ListeContacts.class
Normal file
BIN
chat/bin/model/ListeContacts.class
Normal file
Binary file not shown.
BIN
chat/bin/module-info.class
Normal file
BIN
chat/bin/module-info.class
Normal file
Binary file not shown.
BIN
chat/bin/network/Tools.class
Normal file
BIN
chat/bin/network/Tools.class
Normal file
Binary file not shown.
44
chat/src/model/Contact.java
Normal file
44
chat/src/model/Contact.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package model;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
|
||||||
|
public class Contact {
|
||||||
|
|
||||||
|
private String pseudo;
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private InetAddress address;
|
||||||
|
|
||||||
|
|
||||||
|
public Contact(String pseudo, InetAddress address) {
|
||||||
|
this.pseudo = pseudo;
|
||||||
|
this.address = address;
|
||||||
|
this.status = "En ligne";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPseudo() {
|
||||||
|
return this.pseudo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPseudo(String pseudo) {
|
||||||
|
this.pseudo = pseudo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InetAddress getAddress() {
|
||||||
|
return this.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(InetAddress address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatut() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatut(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
chat/src/model/ListeContacts.java
Normal file
50
chat/src/model/ListeContacts.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package model;
|
||||||
|
|
||||||
|
import network.*;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ListeContacts {
|
||||||
|
private static Contact user;
|
||||||
|
private ArrayList<Contact> listeContact;
|
||||||
|
|
||||||
|
|
||||||
|
//la liste doit être un singleton
|
||||||
|
|
||||||
|
private static final ListeContacts instance = new ListeContacts();
|
||||||
|
|
||||||
|
private ListeContacts() {
|
||||||
|
this.listeContact = new ArrayList<Contact>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ListeContacts getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createUser(String pseudo) {
|
||||||
|
user = new Contact(pseudo, Tools.getLocalIp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contactExist(Contact contact) {
|
||||||
|
for(Contact c : listeContact) {
|
||||||
|
if(c.getPseudo().equals(contact.getPseudo())){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addContact(Contact contact) {
|
||||||
|
if(!contactExist(contact)){
|
||||||
|
System.out.println("Pseudo : "+user.getPseudo()+"ajouté\n");
|
||||||
|
listeContact.add(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteContact(Contact contact) {
|
||||||
|
if(contactExist(contact)){
|
||||||
|
System.out.println("Pseudo : "+user.getPseudo()+"supprimé\n");
|
||||||
|
listeContact.remove(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
chat/src/module-info.java
Normal file
2
chat/src/module-info.java
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module chat {
|
||||||
|
}
|
17
chat/src/network/Tools.java
Normal file
17
chat/src/network/Tools.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package network;
|
||||||
|
import java.net.*;
|
||||||
|
|
||||||
|
public class Tools {
|
||||||
|
|
||||||
|
public static InetAddress getLocalIp(){
|
||||||
|
try{
|
||||||
|
InetAddress address = InetAddress.getLocalHost();
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
catch (UnknownHostException e){
|
||||||
|
System.out.println ("Could not find local address!");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue