import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.control.TextField; import javafx.stage.Stage; import javafx.scene.paint.Color; public class Graph2 extends Application { private int[] is = {}; private final Color[] cs = {Color.RED, Color.BLUE}; private Canvas canvas; public void start(Stage stage) { stage.setTitle("ƒOƒ‰ƒt"); TextField input = new TextField(""); input.setOnAction(e -> { String[] args = input.getText().split(" "); int n = args.length; is = new int[n]; int i; for(i = 0; i < n; i++) { is[i] = Integer.parseInt(args[i]); } paint(canvas.getGraphicsContext2D()); }); canvas = new Canvas(200, 200); GraphicsContext gc = canvas.getGraphicsContext2D(); paint(gc); VBox root = new VBox(); root.setAlignment(Pos.CENTER); root.getChildren().addAll(input, canvas); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } private void paint(GraphicsContext gc) { gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); int scale = 15; int i, n = is.length; for (i = 0; i < n; i++) { gc.setFill(cs[i % cs.length]); gc.fillRect(0, i * scale, is[i] * scale, scale); } } public static void main(String... args) { launch(args); } }