0

I have an array containing potential moves for a board game in one file. The display panel that informs the players of current state of game is in another file. I am trying to display this potential moves array as a menu (or table/combo box) in the display panel but I am having problems accessing the array because both codes are in separate files. Any thoughts on how I could display the contents would be greatly appreciated. The array is in my Main.java which contains loads of code but I will post the display panel code here. The array is in a function that returns nothing and prints to the console okay. I hope I have been able to articulate my problem, apologies in advance. calculatemoves function is in Main.java while displayLabels function is in Displaypanel.java

I have tried to create an object of Main but it is not possible because it extends Application(using JavaFX).

public void calculateMoves(int dice1, int dice2){
    String[] potentialMoves = new String[500];
    int k=0;        
    ....

    System.out.println("reach");
    System.out.println("k: "+k);
    for(k=k-1; k>=0; k--){
        System.out.println(potentialMoves[k]);
    }
    ChoiceBox<String> choiceBox = new ChoiceBox<>();
    choiceBox.getItems().addAll(potentialMoves);
}

public void displayLabels(){
    if(gridSize < 31) {
        int numOfLabels = gridSize;
        int j = 0;
        for (int i = numOfLabels; i > numOfLabels - 31; i--) {
            GridPane.setConstraints(labels[i - 1], 0, j);
            grid.getChildren().addAll(labels[i - 1]);
            j++;
            if (i - 1 == 0) break;
        }
 }

13-7 8-3 13-7 7-2 24-18 8-3 24-18 13-8 24-18 18-13 should be printed as a menu. This is the sort of result I get on my console at the moment.

1
  • 1
    I think that code (minimal reproducible example ) would have been clearer and shorter than the attempt to describe it. Commented Mar 25, 2019 at 7:56

1 Answer 1

1

You can use ComboBox. Porbably its really simple way.

class YourController implements Initializable{
    @FXML
    private JFXComboBox<String> cccombo;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        ArrayList<String> yourArray = new ArrayList<>();
        //fill your array
        cccombo.setItems(FXCollections.observableList(yourArray));
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.