Commit 2d2711b1 authored by Thomas's avatar Thomas
Browse files

Optimize CreateGame view creation and manage errors of integer in a field

parent 0b16322e
package main.java.client.main.controller;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import main.java.client.ClientApp;
......@@ -45,6 +46,9 @@ public class FXCreateGame implements Initializable {
@FXML
private Text errorFields;
@FXML
private Text errorFieldsInteger;
public FXCreateGame(){
this.model = ClientApp.mainCore.getFX().getModel();
......@@ -60,6 +64,9 @@ public class FXCreateGame implements Initializable {
errorFields.setVisible(false);
errorFields.setFill(Color.RED);
errorFieldsInteger.setVisible(false);
errorFieldsInteger.setFill(Color.RED);
chatCombo.getItems().setAll("Oui", "Non");
chatCombo.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<String>() {
......@@ -103,6 +110,7 @@ public class FXCreateGame implements Initializable {
createGame();
break;
case "createGameButtonClose":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
FXHome fxHome = new FXHome();
fxHome.initialize("../fxml/home.fxml", this.stage);
break;
......@@ -132,9 +140,13 @@ public class FXCreateGame implements Initializable {
System.out.println(chat + " " + spectators + " " + colorWhite + " " + limitMove);
ClientApp.mainCore.getMainToData().newGame(userLight, spectators, chat, colorWhite, limitMove, scene);
} catch (NumberFormatException e) {
errorFieldsInteger.setVisible(true);
} catch (Exception e) {
if (this.chatCombo.getValue() == null || this.spectatorsCombo.getValue() == null || this.colorCombo.getValue() == null || this.createGameTextFieldLimitMove.getText().trim().isEmpty()){
errorFields.setVisible(true);
} else {
System.out.println(e);
}
}
......
package main.java.client.main.controller;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.Border;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
......@@ -67,11 +69,11 @@ public class FXHome {
fxProfileConsult.initialize("../fxml/viewProfile.fxml", this.stage);
break;
case "homeButtonCreateGame":
BorderPane layout = FXMLLoader.load(
new URL(FXHome.class.getResource("../fxml/createGame.fxml").toExternalForm())
);
stage.setScene(new Scene(layout));
stage.show();
FXMLLoader loader = new FXMLLoader(getClass().getResource("../fxml/createGame.fxml"));
Parent padre = loader.load();
Scene switcher = new Scene(padre);
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
this.stage.setScene(switcher);
break;
case "homeDeconnection":
FXConnection fxConnection = new FXConnection();
......
......@@ -7,11 +7,8 @@
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ComboBox?>
<?import java.lang.String?>
<?import javafx.collections.FXCollections?>
......@@ -57,6 +54,7 @@
<Text layoutX="51.0" layoutY="233.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Limite de coups" />
<TextField fx:id="createGameTextFieldLimitMove" layoutX="51.0" layoutY="243.0" />
<Text text="* Un ou plusieurs des champs sont vides" fx:id="errorFields" layoutX="51.0" layoutY="313.0" />
<Text text="* Le champ 'Limite de coups' doit être un entier " fx:id="errorFieldsInteger" layoutX="51.0" layoutY="333.0" />
</children>
</Pane>
</center>
......
Supports Markdown
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