Last active
October 12, 2020 07:30
-
-
Save sedj601/06208db95b0553deacc3c4731c1651fc to your computer and use it in GitHub Desktop.
TicTacToc Bare Minimum. StackOverflow Question https://stackoverflow.com/questions/64312457/get-the-selected-cell-row-and-column-number-of-gridpane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.Label?> | |
<?import javafx.scene.layout.ColumnConstraints?> | |
<?import javafx.scene.layout.GridPane?> | |
<?import javafx.scene.layout.RowConstraints?> | |
<?import javafx.scene.layout.StackPane?> | |
<?import javafx.scene.text.Font?> | |
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="650.0" style="-fx-background-color: black;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication6.FXMLDocumentController"> | |
<children> | |
<GridPane hgap="5.0" maxHeight="-Infinity" maxWidth="-Infinity" vgap="5.0"> | |
<columnConstraints> | |
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" /> | |
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" /> | |
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" /> | |
</columnConstraints> | |
<rowConstraints> | |
<RowConstraints maxHeight="200.0" minHeight="200.0" prefHeight="200.0" vgrow="SOMETIMES" /> | |
<RowConstraints maxHeight="200.0" minHeight="200.0" prefHeight="200.0" vgrow="SOMETIMES" /> | |
<RowConstraints maxHeight="200.0" minHeight="200.0" prefHeight="200.0" vgrow="SOMETIMES" /> | |
</rowConstraints> | |
<children> | |
<Label fx:id="lbl0" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl1" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.columnIndex="1"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl2" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.columnIndex="2"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl3" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.rowIndex="1"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl5" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.columnIndex="1" GridPane.rowIndex="1"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl6" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.columnIndex="2" GridPane.rowIndex="1"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl7" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.rowIndex="2"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl8" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.columnIndex="1" GridPane.rowIndex="2"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
<Label fx:id="lbl9" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onMouseClicked="#handleMouseClicked" style="-fx-background-color: white;" GridPane.columnIndex="2" GridPane.rowIndex="2"> | |
<font> | |
<Font size="96.0" /> | |
</font> | |
</Label> | |
</children> | |
</GridPane> | |
</children> | |
</StackPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URL; | |
import java.util.ResourceBundle; | |
import javafx.fxml.FXML; | |
import javafx.fxml.Initializable; | |
import javafx.scene.control.Label; | |
import javafx.scene.input.MouseEvent; | |
/** | |
* | |
* @author sedrick (sedj601) | |
*/ | |
public class FXMLDocumentController implements Initializable { | |
int turn = 0; | |
@FXML | |
public void handleMouseClicked(MouseEvent event) { | |
Label tempLabel = ((Label)event.getSource()); | |
if(tempLabel.getText().isEmpty()) | |
{ | |
if(turn % 2 == 0) | |
{ | |
tempLabel.setText("X"); | |
} | |
else | |
{ | |
tempLabel.setText("O"); | |
} | |
turn++; | |
} | |
} | |
@Override | |
public void initialize(URL url, ResourceBundle rb) { | |
// TODO | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
import javafx.stage.Stage; | |
/** | |
* | |
* @author sedri | |
*/ | |
public class JavaFXApplication6 extends Application { | |
@Override | |
public void start(Stage stage) throws Exception { | |
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); | |
Scene scene = new Scene(root); | |
stage.setScene(scene); | |
stage.show(); | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment