Java Reference
In-Depth Information
Listing 5-12. Wrapper Script to Show a ReversiSquare That Resizes with the Scene
public class ReversiSquareTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(new StackPane(new ReversiSquare()));
primaryStage.setScene(scene);
primaryStage.show();
}
}
Running the completed class produces a distinctive board square that dynamically resizes with the window,
as shown in Figure 5-10 .
Figure 5-10. Single Reversi square that resizes with the window
Building a Resizable Reversi Piece
Creating a Reversi playing piece is done very similarly to how you created a square in the previous section. Your class
should extend Region and have a public owner property that can be set to change the color of the playing piece to
either WHITE or BLACK:
public class ReversiPiece extends Region {
private ObjectProperty<Owner> ownerProperty = new SimpleObjectProperty<>(this, "owner" , Owner.NONE);
public ObjectProperty<Owner> ownerProperty() {
return ownerProperty;
}
public Owner getOwner() {
return ownerProperty.get();
}
public void setOwner(Owner owner) {
ownerProperty.set(owner);
}
 
Search WWH ::




Custom Search