Есть ли способ определить группу кнопок по одному - PullRequest
0 голосов
/ 20 сентября 2018

Я создаю игру для очистки мин, которая содержит 49 кнопок, пользователь нажимает одну из кнопок, и программа будет искать мины вокруг, или она взорвется

Мой вопрос, есть лиспособ определения группы кнопок вместо аннотирования каждой из них в классе контроллера?

    <Text text=" " GridPane.columnIndex="0" GridPane.rowIndex="0"/>
    <Text text=" 1" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
    <Text text=" 2" GridPane.columnIndex="2" GridPane.rowIndex="0"/>
    <Text text=" 3" GridPane.columnIndex="3" GridPane.rowIndex="0"/>
    <Text text=" 4" GridPane.columnIndex="4" GridPane.rowIndex="0"/>
    <Text text=" 5" GridPane.columnIndex="5" GridPane.rowIndex="0"/>
    <Text text=" 6" GridPane.columnIndex="6" GridPane.rowIndex="0"/>
    <Text text=" 7" GridPane.columnIndex="7" GridPane.rowIndex="0"/>

    <Text text="A" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A1" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A2" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A3" GridPane.columnIndex="3" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A4" GridPane.columnIndex="4" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A5" GridPane.columnIndex="5" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A6" GridPane.columnIndex="6" GridPane.rowIndex="1"/>
    <Button text="*" fx:id="A7" GridPane.columnIndex="7" GridPane.rowIndex="1"/>

    <Text text="B" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B1" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B2" GridPane.columnIndex="2" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B3" GridPane.columnIndex="3" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B4" GridPane.columnIndex="4" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B5" GridPane.columnIndex="5" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B6" GridPane.columnIndex="6" GridPane.rowIndex="2"/>
    <Button text="*" fx:id="B7" GridPane.columnIndex="7" GridPane.rowIndex="2"/>

    <Text text="C" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C1" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C2" GridPane.columnIndex="2" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C3" GridPane.columnIndex="3" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C4" GridPane.columnIndex="4" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C5" GridPane.columnIndex="5" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C6" GridPane.columnIndex="6" GridPane.rowIndex="3"/>
    <Button text="*" fx:id="C7" GridPane.columnIndex="7" GridPane.rowIndex="3"/>

    <Text text="D" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D1" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D2" GridPane.columnIndex="2" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D3" GridPane.columnIndex="3" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D4" GridPane.columnIndex="4" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D5" GridPane.columnIndex="5" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D6" GridPane.columnIndex="6" GridPane.rowIndex="4"/>
    <Button text="*" fx:id="D7" GridPane.columnIndex="7" GridPane.rowIndex="4"/>


    <Text text="E" GridPane.columnIndex="0" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E1" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E2" GridPane.columnIndex="2" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E3" GridPane.columnIndex="3" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E4" GridPane.columnIndex="4" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E5" GridPane.columnIndex="5" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E6" GridPane.columnIndex="6" GridPane.rowIndex="5"/>
    <Button text="*" fx:id="E7" GridPane.columnIndex="7" GridPane.rowIndex="5"/>

    <Text text="F" GridPane.columnIndex="0" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F1" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F2" GridPane.columnIndex="2" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F3" GridPane.columnIndex="3" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F4" GridPane.columnIndex="4" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F5" GridPane.columnIndex="5" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F6" GridPane.columnIndex="6" GridPane.rowIndex="6"/>
    <Button text="*" fx:id="F7" GridPane.columnIndex="7" GridPane.rowIndex="6"/>

    <Text text="G" GridPane.columnIndex="0" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G1" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G2" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G3" GridPane.columnIndex="3" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G4" GridPane.columnIndex="4" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G5" GridPane.columnIndex="5" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G6" GridPane.columnIndex="6" GridPane.rowIndex="7"/>
    <Button text="*" fx:id="G7" GridPane.columnIndex="7" GridPane.rowIndex="7"/>

import javafx.fxml.FXML;import javafx.scene.control.Button;

Контроллер открытого класса {

@FXML
private Button A1;
@FXML
private Button A2;
@FXML
private Button A3;
@FXML
private Button A4;
@FXML
private Button A5;
@FXML
private Button A6;
@FXML
private Button A7;
@FXML
private Button B1;
@FXML
private Button B2;
@FXML
private Button B3;
@FXML
private Button B4;
@FXML
private Button B5;
@FXML
private Button B6;
@FXML
private Button B7;
@FXML
private Button C1;
@FXML
private Button C2;
@FXML
private Button C3;
@FXML
private Button C4;
@FXML
private Button C5;
@FXML
private Button C6;
@FXML
private Button C7;
@FXML
private Button E1;
@FXML
private Button E2;
@FXML
private Button E3;
@FXML
private Button E4;
@FXML
private Button E5;
@FXML
private Button E6;
@FXML
private Button E7;
@FXML
private Button F1;
@FXML
private Button F2;
@FXML
private Button F3;
@FXML
private Button F4;
@FXML
private Button F5;
@FXML
private Button F6;
@FXML
private Button F7;
@FXML
private Button G1;
@FXML
private Button G2;
@FXML
private Button G3;
@FXML
private Button G4;
@FXML
private Button G5;
@FXML
private Button G6;
@FXML
private Button G7;

}

...