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