2016-02-09 27 views

回答

1

試試這個。

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.AnchorPane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Rectangle; 
import javafx.stage.Stage; 

public class RectangleDemo extends Application { 

    @Override 
    public void start(Stage stage) { 
     AnchorPane root = new AnchorPane(); 
     Scene scene = new Scene(root); 
     stage.setScene(scene); 

     int columns = 20, rows = 10, horizontal = 50, vertical = 20; 
     Rectangle rect = null; 
     for (int i = 0; i < columns; ++i) { 
      for (int j = 0; j < rows; ++j) { 
       rect = new Rectangle(horizontal * j, vertical * i, horizontal, vertical); 
       rect.setStroke(Color.RED); 
       root.getChildren().add(rect); 
      } 
     } 
     scene.setRoot(root); 
     stage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
}