4 import java.util.ResourceBundle;
6 import fi.jyu.mit.fxgui.StringGrid;
7 import javafx.fxml.FXML;
8 import javafx.fxml.Initializable;
9 import javafx.scene.control.TextArea;
10 import javafx.scene.input.KeyCode;
20 @FXML
private StringGrid<Object>
grid;
21 @FXML
private TextArea
area;
24 private String[]
merkit = {
"X",
"O"};
25 private String[]
tyylit = {
"risti",
"nolla"};
29 public void initialize(URL location, ResourceBundle resources) {
31 grid.getSelectionModel().setCellSelectionEnabled(
true);
32 String[] headings =
new String[
koko+1];
33 String[] tyhja =
new String[
koko+1];
35 for (
int i=1;
i<=
koko;
i++) headings[
i] =
""+
i;
36 grid.initTable(headings);
37 for (
int i=0;
i<
koko+1;
i++) tyhja[
i] =
"";
39 grid.setColumnWidth(-1,30);
40 grid.setSortable(-1,
false);
41 grid.disableColumnReOrder();
46 grid.setStyleClass(
"otsikko",
i-1, 0);
52 grid.setOnKeyPressed( e -> {
if ( e.getCode() == KeyCode.ENTER )
laitaMerkki();});
57 int r =
grid.getRowNr();
58 int c =
grid.getColumnNr();
59 if ( r < 0 || c < 1 )
return;
60 if ( !
grid.get(r, c).isEmpty() )
return;
63 grid.set(merkki, r, c);
64 area.setText(
area.getText() + String.format(
"%s -> (%d,%d)\n", merkki, r+1, c));
65 vuorossa = (vuorossa+1) %
merkit.length;