Write a program that displays a tictactoe board as shown her

Write a program that displays a tic-tac-toe, board as shown here. A cell may be X, O or empty. What to display in each cell is randomly selected. Use the GridPane to control your cells and show the grid lines. Also, use Labels, NOT images!

**NOTE

Tic Tac Toe O X 0)

Solution

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.GridPane;

import javafx.stage.Stage;

public class TicTacToe extends Application {

@Override

public void start(Stage primaryStage) {

GridPane pane = new GridPane();

Image img1 = new Image(\"image/o.gif\");

Image img2 = new Image(\"image/x.gif\");

ImageView imgView1 = new ImageView(img1);

ImageView imgView2 = new ImageView(img2);

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++) {

int random = (int)(Math.random() * 2);

if(random == 0) {

pane.add(imgView1, j, i);

} else {

pane.add(imgView2, j, i);

}

}

}

Scene scene = new Scene(pane);

primaryStage.setTitle(\"Tic-Tac-Toe Board\");

primaryStage.setScene(scene);

primaryStage.show();

}

public static void main(String[] args) {

Application.launch(args);

}

}

Write a program that displays a tic-tac-toe, board as shown here. A cell may be X, O or empty. What to display in each cell is randomly selected. Use the GridPa
Write a program that displays a tic-tac-toe, board as shown here. A cell may be X, O or empty. What to display in each cell is randomly selected. Use the GridPa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site