Archived
1
0
Fork 0

Update dependencies and save connection information

This commit is contained in:
Ziedelth 2021-12-08 09:25:21 +01:00
parent 00effd8b55
commit a9215ccb9a
2 changed files with 36 additions and 5 deletions

View file

@ -34,13 +34,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>

View file

@ -6,8 +6,11 @@ import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.Socket;
import java.util.Properties;
public class ConnectGuiController {
public TextField addressTextField;
@ -35,21 +38,49 @@ public class ConnectGuiController {
// Check if the connection is available
if (this.isAccessible(address, iPort)) {
System.out.println("Connection available, saving file...");
// Save server information in properties file
@NotNull
final Properties properties = new Properties();
properties.setProperty("address", address);
properties.setProperty("port", port);
try {
@NotNull
final File file = new File("connection.properties");
properties.store(new FileWriter(file), "Information needed to connect to the server");
this.showSuccessDialog("Connecté", "Vous êtes bien connecté au serveur");
System.out.println("File saved, next step...");
} catch (IOException e) {
this.showErrorDialog("Erreur", "Impossible de sauvegarder les informations de connexion au serveur");
this.connectButton.setDisable(false);
System.out.println("Failed to save file, error: " + e.getMessage());
}
} else {
System.out.println("Connection not available");
this.showDialog("Erreur de connexion", "Impossible de se connecter au serveur, veuillez vérifier les informations saisies");
this.showErrorDialog("Erreur de connexion", "Impossible de se connecter au serveur, veuillez vérifier les informations saisies");
this.connectButton.setDisable(false);
}
} else {
this.showDialog("Erreur", "Veuillez saisir un numéro de port valide");
this.showErrorDialog("Erreur", "Veuillez saisir un numéro de port valide");
this.connectButton.setDisable(false);
}
}
private void showDialog(String title, String description) {
private void showErrorDialog(String title, String description) {
@NotNull
final Alert alert = new Alert(Alert.AlertType.WARNING);
extracted(title, description, alert);
}
private void showSuccessDialog(String title, String description) {
@NotNull
final Alert alert = new Alert(Alert.AlertType.INFORMATION);
extracted(title, description, alert);
}
private void extracted(String title, String description, @NotNull Alert alert) {
alert.setTitle(title);
alert.setContentText(description);
alert.show();