2016-11-21 53 views

回答

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; 
    } 

}