Advertisement
Guest User

code

a guest
Sep 14th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.scene.Scene;
  3. import javafx.scene.layout.Pane;
  4. import javafx.scene.layout.StackPane;
  5. import javafx.scene.paint.Color;
  6. import javafx.scene.shape.Line;
  7. import javafx.stage.Stage;
  8.  
  9. import java.awt.*;
  10. import java.util.ArrayList;
  11. import java.util.Collections;
  12.  
  13. public class Test extends Application {
  14.  
  15. public static void main(String[] args) {
  16. launch(args);
  17. }
  18.  
  19. static final int WIDTH=800, HEIGHT=400;
  20.  
  21. @Override
  22. public void start(Stage primaryStage) {
  23. Pane container = new Pane();
  24. ArrayList<Integer> a = new ArrayList<Integer>();
  25. a.add(5);
  26. a.add(3);
  27. a.add(5);
  28. a.add(8);
  29. a.add(16);
  30. StackPane sp = getStackPaneFromArray(a);
  31.  
  32. container.getChildren().add(sp);
  33. Scene scene = new Scene(container, 800, 400);
  34. primaryStage.setScene(scene);
  35. primaryStage.show();
  36. }
  37.  
  38.  
  39. static StackPane getStackPaneFromArray(ArrayList<Integer> values) {
  40. StackPane stackPane = new StackPane();
  41.  
  42. int min = Collections.min(values);
  43. int max = Collections.max(values);
  44.  
  45. Point previousPoint = new Point(0,HEIGHT-((values.get(0)-min)*HEIGHT/(max-min)));
  46.  
  47. Line test = new Line(0,HEIGHT-339,200,HEIGHT-339);
  48. test.setStroke(Color.RED);
  49. stackPane.getChildren().add(test);
  50.  
  51. for(int i=1;i<values.size();i++) {
  52. Line line = new Line(previousPoint.x, previousPoint.y, i*WIDTH/(values.size()-1), HEIGHT-((values.get(i)-min)*HEIGHT/(max-min)));
  53. stackPane.getChildren().add(line);
  54. System.out.println("Drawing (" + previousPoint.x + ";" + previousPoint.y + ") to (" + (i*WIDTH/(values.size()-1)) + ";" + (HEIGHT-((values.get(0)-min)*HEIGHT/(max-min))) + ")");
  55. previousPoint = new Point(i*WIDTH/(values.size()-1),HEIGHT-((values.get(0)-min)*HEIGHT/(max-min)));
  56. }
  57. return stackPane;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement