Java Reference
In-Depth Information
board[x][y].setValue(turn.get());
x += directionX;
y += directionY;
}
}
}
With a completed game algorithm, you can now play a full game with two players at the same computer, as
shown in Figure 5-16 . Notice that even the turn indicator that you set up at the beginning of the chapter is now
properly flipping and indicating the current player.
Declaring the User Interface Using FXML
So far, we have created the complete UI for the Reversi application using the JavaFX APIs. Doing so, we
programmatically defined the UI. This approach allows a developer to get a clear insight into the structure and the
behavior of the different components of the UI. As we explained in Chapter 3, it is often interesting to declare a UI
rather than to program it.
Listing 5-18 provides an FXML file that declares the same UI as the one we developed in the previous sections.
Listing 5-18 . The Reversi User Interface Declared in FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<AnchorPane id="AnchorPane" xmlns=" http://javafx.com/javafx/8 " xmlns:fx=" http://javafx.com/fxml/1 "
fx:controller="projavafx.reversifxml.BoardController">
<children>
<BorderPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<TilePane fx:id="titlePane" prefTileHeight="40.0" snapToPixel="false"
BorderPane.alignment="CENTER">
<children>
<StackPane snapToPixel="false" style="-fx-background-color: black;">
<children>
<Text fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0"
text="JavaFX" StackPane.alignment="CENTER_RIGHT">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Text>
</children>
</StackPane>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Reversi"
TilePane.alignment="CENTER_LEFT">
 
Search WWH ::




Custom Search