使用JavaFX的随机块

时间:2016-11-21 00:16:21

标签: random javafx

如何使用JavaFX获取随机块(黑白)?

使用:

Random ran = new Random()

1 个答案:

答案 0 :(得分:0)

这是一种方法,您可以根据需要进行调整:

private void ColoreBlock(Pane p){

    Random random = new Random();
    int randomNum = random.nextInt((1 - 0) + 1) + 0; // range (1-0) white/black

    switch (randomNum) {
    case 0:    
    p.setStyle("-fx-background-color:white;");  // -fx-fill for shape
    break;
    case 1: 
    p.setStyle("-fx-background-color:black;");  // -fx-fill for shape   
    break;
    }

}