It works !
This commit is contained in:
@@ -4,7 +4,7 @@ import java.net.InetSocketAddress;
|
|||||||
|
|
||||||
public class ChatAppClient {
|
public class ChatAppClient {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ClientConsole console = new ClientConsole(new InetSocketAddress("192.168.163.131", 6665));
|
ClientConsole console = new ClientConsole(new InetSocketAddress("localhost", 6665));
|
||||||
try {
|
try {
|
||||||
console.joinThread();
|
console.joinThread();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
package client;
|
package client;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.layout.Border;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import network.protocol.packets.ServerResponsePacket;
|
import network.protocol.packets.ServerResponsePacket;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,30 +17,44 @@ public class ClientGuiController implements ClientListener {
|
|||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private BorderPane vueContainer;
|
||||||
|
|
||||||
public void setClient(Client client) {
|
public void setClient(Client client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() throws SocketException {
|
||||||
|
client = new Client(new InetSocketAddress("localhost", 6665), this, UsernameSingleton.getInstance().getUsername());
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
Stage stage = (Stage) vueContainer.getScene().getWindow();
|
||||||
|
stage.setOnCloseRequest(event -> {
|
||||||
|
client.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDisconnect() {
|
public void handleDisconnect() {
|
||||||
|
System.out.println("Disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleConnexionError() {
|
public void handleConnexionError() {
|
||||||
|
System.out.println("Connection error");
|
||||||
|
System.out.println(UsernameSingleton.getInstance().getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleConnect() {
|
public void handleConnect() {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle("Connection");
|
||||||
|
alert.setHeaderText("Connection to the server successful");
|
||||||
|
alert.showAndWait();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleChatMessage(Instant time, String chatter, String content) {
|
public void handleChatMessage(Instant time, String chatter, String content) {
|
||||||
|
|
||||||
|
|||||||
@@ -15,71 +15,33 @@ import java.util.List;
|
|||||||
|
|
||||||
import static utilities.FxUtilities.centerStage;
|
import static utilities.FxUtilities.centerStage;
|
||||||
|
|
||||||
public class ClientLoading implements ClientListener {
|
public class ClientLoading {
|
||||||
@FXML
|
@FXML
|
||||||
private Arc spinnerArc;
|
private Arc spinnerArc;
|
||||||
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
public void initialize() throws IOException, InterruptedException {
|
public void initialize() throws IOException, InterruptedException {
|
||||||
// Création de l'animation de rotation
|
// Création de l'animation de rotation
|
||||||
RotateTransition rotate = new RotateTransition(Duration.seconds(1), spinnerArc);
|
RotateTransition rotate = new RotateTransition(Duration.seconds(1), spinnerArc);
|
||||||
rotate.setByAngle(360);
|
rotate.setByAngle(360);
|
||||||
rotate.setCycleCount(RotateTransition.INDEFINITE);
|
rotate.setCycleCount(RotateTransition.INDEFINITE);
|
||||||
rotate.play();
|
rotate.play();
|
||||||
}
|
|
||||||
|
|
||||||
public void setClient(Client client) {
|
// new Thread(() -> {
|
||||||
this.client = client;
|
// try {
|
||||||
|
// Thread.sleep(2000);
|
||||||
|
// login();
|
||||||
|
// } catch (IOException | InterruptedException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void login() throws IOException {
|
public void login() throws IOException {
|
||||||
var loader = new FXMLLoader(getClass().getResource("/client/clientVue.fxml"));
|
var loader = new FXMLLoader(getClass().getResource("/client/clientVue.fxml"));
|
||||||
loader.load();
|
loader.load();
|
||||||
client.changeCallback(loader.getController());
|
|
||||||
((ClientGuiController) loader.getController()).setClient(client);
|
|
||||||
Stage stage = (Stage) spinnerArc.getScene().getWindow();
|
Stage stage = (Stage) spinnerArc.getScene().getWindow();
|
||||||
stage.setScene(new Scene(loader.getRoot(), 800, 600));
|
stage.setScene(new Scene(loader.getRoot(), 800, 600));
|
||||||
centerStage(stage);
|
centerStage(stage);
|
||||||
stage.getScene().getStylesheets().add(getClass().getResource("clientStyle.css").toExternalForm());
|
stage.getScene().getStylesheets().add(getClass().getResource("clientStyle.css").toExternalForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleDisconnect() {
|
|
||||||
System.out.println("Disconnected");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleConnexionError() {
|
|
||||||
System.out.println("Connection error");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleConnect() {
|
|
||||||
try {
|
|
||||||
login();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleChatMessage(Instant time, String chatter, String content) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleRoomList(List<String> roomNames) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleServerResponse(ServerResponsePacket.Response response) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleActualRoom(String roomName) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import javafx.fxml.FXMLLoader;
|
|||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import client.ClientGui;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
|
|
||||||
import static utilities.FxUtilities.centerStage;
|
import static utilities.FxUtilities.centerStage;
|
||||||
|
|
||||||
@@ -21,10 +19,9 @@ public class ClientLogin {
|
|||||||
if(username.isEmpty()) {
|
if(username.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
UsernameSingleton.getInstance().setUsername(username);
|
||||||
var loader = new FXMLLoader(getClass().getResource("/client/clientLoading.fxml"));
|
var loader = new FXMLLoader(getClass().getResource("/client/clientLoading.fxml"));
|
||||||
Client client = new Client(new InetSocketAddress("localhost", 6665), loader.getController(), username);
|
|
||||||
loader.load();
|
loader.load();
|
||||||
((ClientLoading) loader.getController()).setClient(client);
|
|
||||||
Stage stage = (Stage) usernameField.getScene().getWindow();
|
Stage stage = (Stage) usernameField.getScene().getWindow();
|
||||||
stage.setScene(new Scene(loader.getRoot(), 800, 600));
|
stage.setScene(new Scene(loader.getRoot(), 800, 600));
|
||||||
centerStage(stage);
|
centerStage(stage);
|
||||||
|
|||||||
24
ChatApp/app/src/main/java/client/UsernameSingleton.java
Normal file
24
ChatApp/app/src/main/java/client/UsernameSingleton.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package client;
|
||||||
|
|
||||||
|
public class UsernameSingleton {
|
||||||
|
private static UsernameSingleton instance;
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private UsernameSingleton() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UsernameSingleton getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new UsernameSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user