diff --git a/build.xml b/build.xml
index 0a8da96..644c1e2 100644
--- a/build.xml
+++ b/build.xml
@@ -49,6 +49,14 @@
+
+
+
+
+
+
+
+
diff --git a/src/ch/epfl/lca/sc250/PlayerProgram.java b/src/ch/epfl/lca/sc250/PlayerProgram.java
index 366697a..8f80499 100644
--- a/src/ch/epfl/lca/sc250/PlayerProgram.java
+++ b/src/ch/epfl/lca/sc250/PlayerProgram.java
@@ -1,17 +1,27 @@
package ch.epfl.lca.sc250;
+import ch.epfl.lca.sc250.gui.finalgui.*;
+
public class PlayerProgram {
TCPClient tcpC;
UDPServer udpS;
ServentServer svS;
ServentClient svC;
+ CnFrameMain gui;
public PlayerProgram ( ) {
- tcpC = new TCPClient("in3sun23.epfl.ch", 13370, "x-way");
+ gui = new CnFrameMain("fdasdf-sdafsadfä-fsad-fsdaf--");
+ tcpC = new TCPClient("in3sun23.epfl.ch", 13370, "x-way", gui);
+ udpS = new UDPServer(gui);
+ svC = new ServentClient(gui);
+ svS = new ServentServer(gui);
}
public void launch ( ) {
+ tcpC.start();
+ udpS.start();
+ svS.start();
}
public static void main ( String[] args ) {
diff --git a/src/ch/epfl/lca/sc250/ServentClient.java b/src/ch/epfl/lca/sc250/ServentClient.java
index 98101e2..97972f5 100644
--- a/src/ch/epfl/lca/sc250/ServentClient.java
+++ b/src/ch/epfl/lca/sc250/ServentClient.java
@@ -1,7 +1,6 @@
package ch.epfl.lca.sc250;
-import ch.epfl.lca.sc250.gui.CnFrameP2P;
-import ch.epfl.lca.sc250.gui.ITCPSender;
+import ch.epfl.lca.sc250.gui.finalgui.*;
import java.net.*;
import java.io.*;
@@ -14,7 +13,7 @@
/**
* Instance of the GUI
*/
- CnFrameP2P myGui;
+ CnFrameMain myGui;
private Socket sock;
private int targetport = 13371;
@@ -27,8 +26,8 @@
*
* @param windowTitle The title of the GUI
*/
- public ServentClient(String windowTitle) {
- myGui = new CnFrameP2P(windowTitle);
+ public ServentClient(CnFrameMain gui) {
+ myGui = gui;
// Give the GUI an instance of the ServentClient
myGui.setTcpSender(this);
}
@@ -38,7 +37,7 @@
* @param args
*/
public static void main(String[] args) {
- new ServentClient(" - Client of Servent - Computer Networking");
+ new ServentClient(new CnFrameMain("abc"));
}
/**
diff --git a/src/ch/epfl/lca/sc250/ServentServer.java b/src/ch/epfl/lca/sc250/ServentServer.java
index eea17a5..45760a4 100644
--- a/src/ch/epfl/lca/sc250/ServentServer.java
+++ b/src/ch/epfl/lca/sc250/ServentServer.java
@@ -5,17 +5,30 @@
import java.io.*;
import java.net.*;
+import ch.epfl.lca.sc250.gui.finalgui.*;
+
/**
* @author Christophe Trefois
*
*/
-public class ServentServer {
+public class ServentServer extends Thread {
+
+ private CnFrameMain gui;
public static void main(String[] args) {
- ServentServer s = new ServentServer();
+ ServentServer s = new ServentServer(new CnFrameMain("abc"));
+ s.loop();
}
- public ServentServer ( ) {
+ public ServentServer ( CnFrameMain gui ) {
+ this.gui = gui;
+ }
+
+ public void run ( ) {
+ this.loop();
+ }
+
+ public void loop ( ) {
// Open a Socket and listen on incoming offer requests.
//
try {
@@ -41,7 +54,7 @@
String[] parsed = message.split(", ");
// We suppose we got and parsed an offer, we then want the pop-up to display
- result = getOfferResult(sock.getInetAddress().toString(), parsed[0], parsed[1]);
+ result = gui.getOfferResult(sock.getInetAddress().toString(), parsed[0], parsed[1]);
if(result) {
System.out.println("Yes");
@@ -58,25 +71,4 @@
e.printStackTrace();
}
}
-
- /**
- * When an offer is received, display a Confirm Dialog where the user can choose Yes or No
- * @param IP The IP we got the offer from
- * @param amount The amount the other player gives us for a letter
- * @param position The position of the letter he wants to buy
- * @return True or False
- */
-
- public static boolean getOfferResult(String IP, String amount, String position) {
- boolean chosenValue = false;
- String msgToDisplay = "Buyer from IP: " + IP + "\nWants to buy Letter at Position " + position + " for " + amount + "$";
- int returnValue = JOptionPane.showConfirmDialog(null, msgToDisplay, "You got an Offer !", JOptionPane.YES_NO_OPTION);
- if(returnValue == JOptionPane.OK_OPTION) {
- chosenValue = true;
- } else {
- chosenValue = false;
- }
- return chosenValue;
- }
-
}
diff --git a/src/ch/epfl/lca/sc250/TCPClient.java b/src/ch/epfl/lca/sc250/TCPClient.java
index e0954c2..64a03b2 100644
--- a/src/ch/epfl/lca/sc250/TCPClient.java
+++ b/src/ch/epfl/lca/sc250/TCPClient.java
@@ -3,9 +3,9 @@
import java.net.*;
import java.io.*;
-import ch.epfl.lca.sc250.gui.*;
+import ch.epfl.lca.sc250.gui.finalgui.*;
-public class TCPClient {
+public class TCPClient extends Thread {
private Socket sock;
@@ -18,18 +18,26 @@
private BufferedReader inr;
private DataOutputStream outs;
- private CnFrameTCP gui;
+ private CnFrameMain gui;
public static void main ( String[] args ) {
- TCPClient tc = new TCPClient("in3sun23.epfl.ch", 13370, "x-way");
- tc.join();
+ TCPClient tc = new TCPClient("in3sun23.epfl.ch", 13370, "x-way", new CnFrameMain("abc"));
+ tc.init();
+ tc.joinGame();
tc.loop();
tc.leave();
}
- void loop ( ) {
+ public void run ( ) {
+ this.init();
+ this.joinGame();
+ this.loop();
+ this.leave();
+ }
+
+ public void loop ( ) {
boolean finished = false;
@@ -55,11 +63,14 @@
}
}
- TCPClient ( String targethost, int targetport, String name ) {
- gui = new CnFrameTCP("TCPClient");
+ TCPClient ( String targethost, int targetport, String name, CnFrameMain gui ) {
+ this.gui = gui;
this.targethost = targethost;
this.targetport = targetport;
this.name = name;
+ }
+
+ public void init ( ) {
try {
sock = new Socket(targethost, targetport);
@@ -83,7 +94,7 @@
}
}
- public void join ( ) {
+ public void joinGame ( ) {
write("Hello: " + name + "\n");
String t = read();
System.out.println(t);
diff --git a/src/ch/epfl/lca/sc250/UDPServer.java b/src/ch/epfl/lca/sc250/UDPServer.java
index 9a76665..f334979 100644
--- a/src/ch/epfl/lca/sc250/UDPServer.java
+++ b/src/ch/epfl/lca/sc250/UDPServer.java
@@ -4,19 +4,19 @@
import java.io.*;
import java.nio.*;
-import ch.epfl.lca.sc250.gui.*;
+import ch.epfl.lca.sc250.gui.finalgui.*;
-public class UDPServer {
+public class UDPServer extends Thread {
private DatagramSocket sock;
- private CnFrameUDP gui;
+ private CnFrameMain gui;
public static void main ( String[] args ) {
- UDPServer udpS = new UDPServer();
+ UDPServer udpS = new UDPServer(new CnFrameMain("abc"));
udpS.loop();
}
- UDPServer ( ) {
- gui = new CnFrameUDP("UDPServer");
+ UDPServer ( CnFrameMain gui ) {
+ this.gui = gui;
try {
sock = new DatagramSocket(13371);
} catch ( SocketException se ) {
@@ -24,6 +24,10 @@
}
}
+ public void run ( ) {
+ this.loop();
+ }
+
public void loop ( ) {
int buffsize = 4096;
byte[] buff = new byte[buffsize];
diff --git a/src/ch/epfl/lca/sc250/gui/finalgui/CnFrameMain.java b/src/ch/epfl/lca/sc250/gui/finalgui/CnFrameMain.java
index c1161b0..965fc99 100644
--- a/src/ch/epfl/lca/sc250/gui/finalgui/CnFrameMain.java
+++ b/src/ch/epfl/lca/sc250/gui/finalgui/CnFrameMain.java
@@ -110,7 +110,7 @@
JSplitPane sp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, sp, createTCPPanel());
- add(sp2, BorderLayout.CENTER);
+ getContentPane().add(sp2, BorderLayout.CENTER);
setVisible(true);