Question
I need to write a Java program that emulates a tic tac toe game. Currently I have my code for the login for both players:
I need to write a Java program that emulates a tic tac toe game. Currently I have my code for the login for both players:
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage;
public class Login extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("My TicTac Toe"); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25));
Text scenetitle = new Text("Welcome"); scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 2, 1);
Label plyr1 = new Label("Player 1 Name "); grid.add(plyr1, 0, 1);
TextField userTextField1 = new TextField(); grid.add(userTextField1, 1, 1);
Label plyr2 = new Label("Player 2 Name"); grid.add(plyr2, 0, 2);
TextField userTextField2 = new TextField(); grid.add(userTextField2, 1, 2);
Button btn = new Button("Start"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4);
final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6);
btn.setOnAction(new EventHandler
@Override public void handle(ActionEvent e) { actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Credentials are submitted Successfully"); } }); Button btn = new Button("Cancel"); btn.setOnAction(new ExitButtonListener(){ @Override public void handle(ActionEvent arg0) { Platform.exit(); } } Scene scene = new Scene(grid, 300, 275); primaryStage.setScene(scene); primaryStage.show(); } }
But I need to get it so that I can place the players names on the board and have a functioning board that looks like the following:
My TicTacToe Player 1 Name Blue Player 2 Name Red Start Cancel
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started