fork download
  1. //'main' method must be in a class 'Rextester'.
  2. //Compiler version 1.8.0_111
  3.  
  4. package Graphics;
  5.  
  6. import javafx.application.Application;
  7. import javafx.scene.Group;
  8. import javafx.scene.Scene;
  9. import javafx.scene.input.KeyCode;
  10. import javafx.scene.paint.Color;
  11. import javafx.scene.shape.Polygon;
  12. import javafx.scene.shape.Rectangle;
  13. import javafx.scene.transform.Rotate;
  14. import javafx.scene.transform.Scale;
  15. import javafx.stage.Stage;
  16.  
  17. import java.util.Random;
  18.  
  19.  
  20. public class Second extends Application {
  21. private static Random random;
  22. private final double[] trianglePoints = new double[] {650, 70, 750, 220, 550, 220};
  23. private final double x = 250, y = 100, width = 100, height = 100;
  24. private final double moveX = 10, moveY = 20;
  25. private final double theta = 135;
  26.  
  27. public static void main(String[] args) {
  28. launch(args);
  29. }
  30.  
  31. @Override
  32. public void start(Stage window) {
  33. random = new Random();
  34.  
  35. Group group = new Group();
  36.  
  37. Rectangle rectangle = new Rectangle(x, y, width, height);
  38. Polygon triangle = new Polygon(trianglePoints);
  39. Color rectColor = getColor(random);
  40. rectangle.setFill(rectColor);
  41. triangle.setFill(getColor(random));
  42.  
  43. group.getChildren().addAll(rectangle, triangle);
  44.  
  45. Scene scene = new Scene(group, 1000, 400, Color.LIGHTGRAY);
  46.  
  47. scene.setOnKeyPressed(e -> {
  48. if (e.getCode() == KeyCode.C) {
  49.  
  50. rectangle.setFill(getColor(random));
  51. triangle.setFill(getColor(random));
  52.  
  53. } else if (e.getCode() == KeyCode.DIGIT1) {
  54. Rotate rectRotate = new Rotate();
  55.  
  56. rectRotate.setAngle(theta);
  57. rectRotate.setPivotX(rectangle.getX() + rectangle.getWidth() / 2);
  58. rectRotate.setPivotY(rectangle.getY() + rectangle.getHeight() / 2);
  59.  
  60. rectangle.getTransforms().add(rectRotate);
  61. rectangle.setFill(triangle.getFill());
  62.  
  63. } else if (e.getCode() == KeyCode.DIGIT2) {
  64. Scale rectScale = new Scale();
  65.  
  66. rectScale.setX(2);
  67. rectScale.setY(2);
  68. rectScale.setPivotX(rectangle.getX() + rectangle.getWidth() / 2);
  69. rectScale.setPivotY(rectangle.getY() + rectangle.getHeight() / 2);
  70.  
  71. rectangle.getTransforms().add(rectScale);
  72. rectangle.setFill(triangle.getFill());
  73.  
  74. } else if (e.getCode() == KeyCode.DIGIT3) {
  75.  
  76. rectangle.setX(rectangle.getX() + moveX);
  77. rectangle.setY(rectangle.getY() + moveY);
  78.  
  79. rectangle.setFill(triangle.getFill());
  80.  
  81. } else if (e.getCode() == KeyCode.SPACE) {
  82.  
  83. rectangle.getTransforms().clear();
  84. rectangle.setX(x);
  85. rectangle.setY(y);
  86. rectangle.setFill(rectColor);
  87.  
  88. }
  89. });
  90.  
  91. window.setTitle("Labrador 2");
  92. window.setScene(scene);
  93. window.show();
  94. }
  95.  
  96. public Color getColor(Random r) {
  97. return Color.color(r.nextDouble(), r.nextDouble(), r.nextDouble());
  98. }
  99. }
  100.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:20: error: class Second is public, should be declared in a file named Second.java
public class Second extends Application {
       ^
Main.java:6: error: package javafx.application does not exist
import javafx.application.Application;
                         ^
Main.java:7: error: package javafx.scene does not exist
import javafx.scene.Group;
                   ^
Main.java:8: error: package javafx.scene does not exist
import javafx.scene.Scene;
                   ^
Main.java:9: error: package javafx.scene.input does not exist
import javafx.scene.input.KeyCode;
                         ^
Main.java:10: error: package javafx.scene.paint does not exist
import javafx.scene.paint.Color;
                         ^
Main.java:11: error: package javafx.scene.shape does not exist
import javafx.scene.shape.Polygon;
                         ^
Main.java:12: error: package javafx.scene.shape does not exist
import javafx.scene.shape.Rectangle;
                         ^
Main.java:13: error: package javafx.scene.transform does not exist
import javafx.scene.transform.Rotate;
                             ^
Main.java:14: error: package javafx.scene.transform does not exist
import javafx.scene.transform.Scale;
                             ^
Main.java:15: error: package javafx.stage does not exist
import javafx.stage.Stage;
                   ^
Main.java:20: error: cannot find symbol
public class Second extends Application {
                            ^
  symbol: class Application
Main.java:32: error: cannot find symbol
    public void start(Stage window) {
                      ^
  symbol:   class Stage
  location: class Second
Main.java:96: error: cannot find symbol
    public Color getColor(Random r) {
           ^
  symbol:   class Color
  location: class Second
Main.java:28: error: cannot find symbol
        launch(args);
        ^
  symbol:   method launch(String[])
  location: class Second
Main.java:31: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:35: error: cannot find symbol
        Group group = new Group();
        ^
  symbol:   class Group
  location: class Second
Main.java:35: error: cannot find symbol
        Group group = new Group();
                          ^
  symbol:   class Group
  location: class Second
Main.java:37: error: cannot find symbol
        Rectangle rectangle = new Rectangle(x, y, width, height);
        ^
  symbol:   class Rectangle
  location: class Second
Main.java:37: error: cannot find symbol
        Rectangle rectangle = new Rectangle(x, y, width, height);
                                  ^
  symbol:   class Rectangle
  location: class Second
Main.java:38: error: cannot find symbol
        Polygon triangle = new Polygon(trianglePoints);
        ^
  symbol:   class Polygon
  location: class Second
Main.java:38: error: cannot find symbol
        Polygon triangle = new Polygon(trianglePoints);
                               ^
  symbol:   class Polygon
  location: class Second
Main.java:39: error: cannot find symbol
        Color rectColor = getColor(random);
        ^
  symbol:   class Color
  location: class Second
Main.java:45: error: cannot find symbol
        Scene scene = new Scene(group, 1000, 400, Color.LIGHTGRAY);
        ^
  symbol:   class Scene
  location: class Second
Main.java:45: error: cannot find symbol
        Scene scene = new Scene(group, 1000, 400, Color.LIGHTGRAY);
                          ^
  symbol:   class Scene
  location: class Second
Main.java:45: error: cannot find symbol
        Scene scene = new Scene(group, 1000, 400, Color.LIGHTGRAY);
                                                  ^
  symbol:   variable Color
  location: class Second
Main.java:48: error: cannot find symbol
            if (e.getCode() == KeyCode.C) {
                               ^
  symbol:   variable KeyCode
  location: class Second
Main.java:53: error: cannot find symbol
            } else if (e.getCode() == KeyCode.DIGIT1) {
                                      ^
  symbol:   variable KeyCode
  location: class Second
Main.java:54: error: cannot find symbol
                Rotate rectRotate = new Rotate();
                ^
  symbol:   class Rotate
  location: class Second
Main.java:54: error: cannot find symbol
                Rotate rectRotate = new Rotate();
                                        ^
  symbol:   class Rotate
  location: class Second
Main.java:63: error: cannot find symbol
            } else if (e.getCode() == KeyCode.DIGIT2) {
                                      ^
  symbol:   variable KeyCode
  location: class Second
Main.java:64: error: cannot find symbol
                Scale rectScale = new Scale();
                ^
  symbol:   class Scale
  location: class Second
Main.java:64: error: cannot find symbol
                Scale rectScale = new Scale();
                                      ^
  symbol:   class Scale
  location: class Second
Main.java:74: error: cannot find symbol
            } else if (e.getCode() == KeyCode.DIGIT3) {
                                      ^
  symbol:   variable KeyCode
  location: class Second
Main.java:81: error: cannot find symbol
            } else if (e.getCode() == KeyCode.SPACE) {
                                      ^
  symbol:   variable KeyCode
  location: class Second
Main.java:97: error: cannot find symbol
        return Color.color(r.nextDouble(), r.nextDouble(), r.nextDouble());
               ^
  symbol:   variable Color
  location: class Second
36 errors
stdout
Standard output is empty