javafx.scene.shape.Circle Java Examples
The following examples show how to use
javafx.scene.shape.Circle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GravityFactory.java From FXGLGames with MIT License | 6 votes |
@Spawns("player") public Entity newPlayer(SpawnData data) { PhysicsComponent physics = new PhysicsComponent(); physics.setBodyType(BodyType.DYNAMIC); Texture staticTexture = FXGL.getAssetLoader() .loadTexture("dude.png") .subTexture(new Rectangle2D(0, 0, 32, 42)); Texture animatedTexture = FXGL.getAssetLoader() .loadTexture("dude.png") .toAnimatedTexture(4, Duration.seconds(1)); return FXGL.entityBuilder() .at(data.getX(), data.getY()) .type(ScifiType.PLAYER) .bbox(new HitBox("main", BoundingShape.circle(19))) .view(new Circle(19, 19, 19, Color.BLUE)) .with(physics) //.with(new PlayerComponent(staticTexture, animatedTexture)) .build(); }
Example #2
Source File: EyesView.java From narjillos with MIT License | 6 votes |
public EyesView(Narjillo narjillo) { this.narjillo = narjillo; Fiber fiber = narjillo.getBody().getHead().getFiber(); this.eyeRed = fiber.getPercentOfRed(); this.eyeGreen = fiber.getPercentOfGreen(); this.eyeBlue = fiber.getPercentOfBlue(); // "Random qualities": we want something that looks random across narjillos, // but stays the same for the same narjillo even after saving and reloading double someRandomQuality = narjillo.getBody().getAdultMass(); double someOtherRandomQuality = narjillo.getBody().getEnergyToChildren(); this.eye1 = new Circle(someRandomQuality % 5 + 7); this.eye2 = new Circle(someOtherRandomQuality % 5 + 7); this.pupil1 = new Circle(Math.min(eye1.getRadius() - 2, someRandomQuality % 6 + 1)); this.pupil2 = new Circle(Math.min(eye1.getRadius() - 2, someOtherRandomQuality % 6 + 1)); eyeCenteringTranslation = eye1.getRadius() - eye2.getRadius(); pupilTranslation = Math.min(eye2.getRadius() - pupil2.getRadius(), eye1.getRadius() - pupil1.getRadius()); this.eye1.getTransforms().add(new Translate(eyeCenteringTranslation - eye1.getRadius() + 1, 0)); this.eye2.getTransforms().add(new Translate(eyeCenteringTranslation + eye2.getRadius() - 1, 0)); }
Example #3
Source File: GravityFactory.java From FXGLGames with MIT License | 6 votes |
@Spawns("key") public Entity newKey(SpawnData data) { PhysicsComponent physics = new PhysicsComponent(); physics.setBodyType(BodyType.DYNAMIC); FixtureDef fd = new FixtureDef(); fd.setDensity(0.03f); physics.setFixtureDef(fd); return FXGL.entityBuilder() .at(data.getX(), data.getY()) .type(ScifiType.KEY) .viewWithBBox(new Circle(10, 10, 10, Color.GOLD)) .with(physics) .build(); }
Example #4
Source File: UserDetail.java From DashboardFx with GNU General Public License v3.0 | 6 votes |
@Override public Node icon() { Image image = new Image(getClass().getResource("/com/gn/media/img/avatar.png").toExternalForm()); ImageView imageView = new ImageView(image); imageView.setFitHeight(30); imageView.setFitWidth(30); Circle circle = new Circle(12); circle.setStroke(Color.WHITE); circle.setStrokeWidth(5); circle.setCenterX(imageView.getFitWidth() / 2); circle.setCenterY(imageView.getFitHeight() / 2); imageView.setClip(circle); return imageView; }
Example #5
Source File: HangmanMain.java From FXTutorials with MIT License | 6 votes |
public HangmanImage() { Circle head = new Circle(20); head.setTranslateX(SPINE_START_X); Line spine = new Line(); spine.setStartX(SPINE_START_X); spine.setStartY(SPINE_START_Y); spine.setEndX(SPINE_END_X); spine.setEndY(SPINE_END_Y); Line leftArm = new Line(); leftArm.setStartX(SPINE_START_X); leftArm.setStartY(SPINE_START_Y); leftArm.setEndX(SPINE_START_X + 40); leftArm.setEndY(SPINE_START_Y + 10); Line rightArm = new Line(); rightArm.setStartX(SPINE_START_X); rightArm.setStartY(SPINE_START_Y); rightArm.setEndX(SPINE_START_X - 40); rightArm.setEndY(SPINE_START_Y + 10); Line leftLeg = new Line(); leftLeg.setStartX(SPINE_END_X); leftLeg.setStartY(SPINE_END_Y); leftLeg.setEndX(SPINE_END_X + 25); leftLeg.setEndY(SPINE_END_Y + 50); Line rightLeg = new Line(); rightLeg.setStartX(SPINE_END_X); rightLeg.setStartY(SPINE_END_Y); rightLeg.setEndX(SPINE_END_X - 25); rightLeg.setEndY(SPINE_END_Y + 50); getChildren().addAll(head, spine, leftArm, rightArm, leftLeg, rightLeg); lives.set(getChildren().size()); }
Example #6
Source File: BreakoutApp.java From FXGLGames with MIT License | 6 votes |
private void setLevel(int levelNum) { getGameWorld().getEntitiesCopy().forEach(e -> e.removeFromWorld()); setLevelFromMap("tmx/level" + levelNum + ".tmx"); var ball = spawn("ball", getAppWidth() / 2, getAppHeight() - 250); ball.getComponent(BallComponent.class).colorProperty().addListener((obs, old, newValue) -> { var circle = (Circle) getGameWorld().getSingleton(COLOR_CIRCLE).getViewComponent().getChildren().get(0); circle.setFill(getBallControl().getNextColor()); }); spawn("bat", getAppWidth() / 2, getAppHeight() - 180); animateCamera(() -> { getSceneService().pushSubScene(new NewLevelSubScene(levelNum)); getBallControl().release(); }); }
Example #7
Source File: BreakoutApp.java From FXGLGames with MIT License | 6 votes |
private void setLevel(int levelNum) { getGameWorld().getEntitiesCopy().forEach(e -> e.removeFromWorld()); setLevelFromMap("tmx/level" + levelNum + ".tmx"); var ball = spawn("ball", getAppWidth() / 2, getAppHeight() - 250); ball.getComponent(BallComponent.class).colorProperty().addListener((obs, old, newValue) -> { var circle = (Circle) getGameWorld().getSingleton(COLOR_CIRCLE).getViewComponent().getChildren().get(0); circle.setFill(getBallControl().getNextColor()); }); spawn("bat", getAppWidth() / 2, getAppHeight() - 180); animateCamera(() -> { getSceneService().pushSubScene(new NewLevelSubScene(levelNum)); getBallControl().release(); }); }
Example #8
Source File: ZoneSelector.java From AnchorFX with GNU Lesser General Public License v3.0 | 6 votes |
private void buildUI(Image image, double x, double y) { setPrefWidth(image.getWidth()); setPrefHeight(image.getHeight()); iconView = new ImageView(image); setStyle("-fx-background-color:rgba(0,0,0,0);"); iconCircle = new Circle(image.getWidth()/2+10); iconCircle.setCenterX(getPrefWidth() / 2); iconCircle.setCenterY(getPrefHeight() / 2); iconCircle.getStyleClass().add("dockzone-circle-selector"); iconView.relocate((getPrefWidth()-image.getWidth()) / 2, (getPrefWidth()-image.getHeight()) / 2); getChildren().addAll(iconCircle,iconView); parent.getChildren().add(this); relocate(x, y); }
Example #9
Source File: CircleSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public CircleSample() { super(180,90); // Simple red filled circle Circle circle1 = new Circle(45,45,40, Color.RED); // Blue stroked circle Circle circle2 = new Circle(135,45,40); circle2.setStroke(Color.DODGERBLUE); circle2.setFill(null); // Create a group to show all the circles); getChildren().add(new Group(circle1,circle2)); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Circle 1 Fill", circle1.fillProperty()), new SimplePropertySheet.PropDesc("Circle 1 Radius", circle1.radiusProperty(), 10d, 40d), new SimplePropertySheet.PropDesc("Circle 2 Stroke", circle2.strokeProperty()), new SimplePropertySheet.PropDesc("Circle 2 Stroke Width", circle2.strokeWidthProperty(), 1d, 5d), new SimplePropertySheet.PropDesc("Circle 2 Radius", circle2.radiusProperty(), 10d, 40d) ); // END REMOVE ME }
Example #10
Source File: FarCry4Loading.java From FXTutorials with MIT License | 6 votes |
public LoadingCircle() { Circle circle = new Circle(20); circle.setFill(null); circle.setStroke(Color.WHITE); circle.setStrokeWidth(2); Rectangle rect = new Rectangle(20, 20); Shape shape = Shape.subtract(circle, rect); shape.setFill(Color.WHITE); getChildren().add(shape); animation = new RotateTransition(Duration.seconds(2.5), this); animation.setByAngle(-360); animation.setInterpolator(Interpolator.LINEAR); animation.setCycleCount(Animation.INDEFINITE); animation.play(); }
Example #11
Source File: PieSkin.java From WorkbenchFX with Apache License 2.0 | 6 votes |
@Override public void initializeParts() { double center = ARTBOARD_HEIGHT * 0.5; border = new Circle(center, center, center); border.getStyleClass().add("border"); pieSlice = new Arc(center, center, center - 1, center - 1, 90, 0); pieSlice.getStyleClass().add("pieSlice"); pieSlice.setType(ArcType.ROUND); valueField = new TextField(); valueField.relocate(ARTBOARD_HEIGHT + 5, 2); valueField.setPrefWidth(ARTBOARD_WIDTH - ARTBOARD_HEIGHT - 5); valueField.getStyleClass().add("valueField"); // always needed drawingPane = new Pane(); drawingPane.setMaxSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT); drawingPane.setMinSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT); drawingPane.setPrefSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT); }
Example #12
Source File: FunLevelGauge.java From medusademo with Apache License 2.0 | 6 votes |
private void initGraphics() { ring = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5 , PREFERRED_WIDTH * 0.5); ring.setFill(Color.TRANSPARENT); ring.setStroke(color); canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT); ctx = canvas.getGraphicsContext2D(); ctx.setFill(color); mask = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.45); canvas.setClip(mask); text = new Text(String.format(Locale.US, "%.0f%%", gauge.getCurrentValue())); text.setFill(darkerColor); text.setTextOrigin(VPos.CENTER); pane = new Pane(ring, canvas, text); getChildren().setAll(pane); }
Example #13
Source File: TranslateTransitionSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public TranslateTransitionSample() { super(400,40); Circle circle = new Circle(20, Color.CRIMSON); circle.setTranslateX(20); circle.setTranslateY(20); getChildren().add(circle); translateTransition = new TranslateTransition(Duration.seconds(4),circle); translateTransition.setFromX(20); translateTransition.setToX(380); translateTransition.setCycleCount(Timeline.INDEFINITE); translateTransition.setAutoReverse(true); translateTransition = TranslateTransitionBuilder.create() .duration(Duration.seconds(4)) .node(circle) .fromX(20) .toX(380) .cycleCount(Timeline.INDEFINITE) .autoReverse(true) .build(); }
Example #14
Source File: Indicator.java From tilesfx with Apache License 2.0 | 6 votes |
private void initGraphics() { if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) { if (getPrefWidth() > 0 && getPrefHeight() > 0) { setPrefSize(getPrefWidth(), getPrefHeight()); } else { setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } getStyleClass().add("indicator"); ring = new Circle(PREFERRED_WIDTH * 0.5); ring.setStrokeType(StrokeType.INSIDE); ring.setStrokeWidth(PREFERRED_WIDTH * 0.078125); ring.setStroke(getRingColor()); ring.setFill(Color.TRANSPARENT); dot = new Circle(PREFERRED_WIDTH * 0.3125); dot.setFill(getDotOnColor()); pane = new Pane(ring, dot); getChildren().setAll(pane); }
Example #15
Source File: LedTileSkin.java From tilesfx with Apache License 2.0 | 6 votes |
@Override protected void initGraphics() { super.initGraphics(); titleText = new Text(); titleText.setFill(tile.getTitleColor()); Helper.enableNode(titleText, !tile.getTitle().isEmpty()); text = new Text(tile.getText()); text.setFill(tile.getUnitColor()); Helper.enableNode(text, tile.isTextVisible()); description = new Label(tile.getDescription()); description.setAlignment(tile.getDescriptionAlignment()); description.setWrapText(true); description.setTextFill(tile.getTextColor()); Helper.enableNode(description, !tile.getDescription().isEmpty()); ledBorder = new Circle(); led = new Circle(); hightlight = new Circle(); innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * size, 0, 0, 0); led.setEffect(innerShadow); getPane().getChildren().addAll(titleText, text, description, ledBorder, led, hightlight); }
Example #16
Source File: CircleSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public CircleSample() { super(180,90); // Simple red filled circle Circle circle1 = new Circle(45,45,40, Color.RED); // Blue stroked circle Circle circle2 = new Circle(135,45,40); circle2.setStroke(Color.DODGERBLUE); circle2.setFill(null); // Create a group to show all the circles); getChildren().add(new Group(circle1,circle2)); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Circle 1 Fill", circle1.fillProperty()), new SimplePropertySheet.PropDesc("Circle 1 Radius", circle1.radiusProperty(), 10d, 40d), new SimplePropertySheet.PropDesc("Circle 2 Stroke", circle2.strokeProperty()), new SimplePropertySheet.PropDesc("Circle 2 Stroke Width", circle2.strokeWidthProperty(), 1d, 5d), new SimplePropertySheet.PropDesc("Circle 2 Radius", circle2.radiusProperty(), 10d, 40d) ); // END REMOVE ME }
Example #17
Source File: DigitalClock.java From netbeans with Apache License 2.0 | 5 votes |
public Clock(Color onColor, Color offColor) { // create effect for on LEDs Glow onEffect = new Glow(1.7f); onEffect.setInput(new InnerShadow()); // create effect for on dot LEDs Glow onDotEffect = new Glow(1.7f); onDotEffect.setInput(new InnerShadow(5,Color.BLACK)); // create effect for off LEDs InnerShadow offEffect = new InnerShadow(); // create digits digits = new Digit[7]; for (int i = 0; i < 6; i++) { Digit digit = new Digit(onColor, offColor, onEffect, offEffect); digit.setLayoutX(i * 80 + ((i + 1) % 2) * 20); digits[i] = digit; getChildren().add(digit); } // create dots Group dots = new Group( new Circle(80 + 54 + 20, 44, 6, onColor), new Circle(80 + 54 + 17, 64, 6, onColor), new Circle((80 * 3) + 54 + 20, 44, 6, onColor), new Circle((80 * 3) + 54 + 17, 64, 6, onColor)); dots.setEffect(onDotEffect); getChildren().add(dots); // update digits to current time and start timer to update every second refreshClocks(); play(); }
Example #18
Source File: ClearIcon.java From FxDock with Apache License 2.0 | 5 votes |
public ClearIcon(double size) { super(size); double r = 0.4 * size; double w = 0.075 * size; double d = 0.14 * size; Circle c = new Circle(0, 0, r); c.setFill(null); c.setStrokeWidth(0); c.setStroke(null); c.setFill(Color.LIGHTGRAY); FxPath p = new FxPath(); p.setStrokeLineCap(StrokeLineCap.SQUARE); p.setStroke(Color.WHITE); p.setStrokeWidth(w); p.moveto(-d, -d); p.lineto(d, d); p.moveto(d, -d); p.lineto(-d, d); Group g = new Group(c, p); g.setTranslateX(size * 0.5); g.setTranslateY(size * 0.5); add(g); }
Example #19
Source File: Exercise_14_11.java From Intro-to-Java-Programming with MIT License | 5 votes |
/** Return a Arc of specified properties */ private Arc getArc(Circle c) { Arc a = new Arc(c.getRadius(), c.getRadius() * 1.30, c.getRadius() / 2, c.getRadius() / 4, 0, -180); a.setType(ArcType.OPEN); a.setFill(Color.WHITE); a.setStroke(Color.BLACK); return a; }
Example #20
Source File: CarPane.java From Intro-to-Java-Programming with MIT License | 5 votes |
/** Create a car an place it in the pane */ private void drawCar() { getChildren().clear(); rectangle = new Rectangle(x, y - 20, 50, 10); polygon = new Polygon(x + 10, y - 20, x + 20, y - 30, x + 30, y - 30, x + 40, y - 20); circle1 = new Circle(x + 15, y - 5, radius); circle2 = new Circle(x + 35, y - 5, radius); getChildren().addAll(rectangle, circle1, circle2, polygon); }
Example #21
Source File: DigitalClock.java From marathonv5 with Apache License 2.0 | 5 votes |
public Clock(Color onColor, Color offColor) { // create effect for on LEDs Glow onEffect = new Glow(1.7f); onEffect.setInput(new InnerShadow()); // create effect for on dot LEDs Glow onDotEffect = new Glow(1.7f); onDotEffect.setInput(new InnerShadow(5,Color.BLACK)); // create effect for off LEDs InnerShadow offEffect = new InnerShadow(); // create digits digits = new Digit[7]; for (int i = 0; i < 6; i++) { Digit digit = new Digit(onColor, offColor, onEffect, offEffect); digit.setLayoutX(i * 80 + ((i + 1) % 2) * 20); digits[i] = digit; getChildren().add(digit); } // create dots Group dots = new Group( new Circle(80 + 54 + 20, 44, 6, onColor), new Circle(80 + 54 + 17, 64, 6, onColor), new Circle((80 * 3) + 54 + 20, 44, 6, onColor), new Circle((80 * 3) + 54 + 17, 64, 6, onColor)); dots.setEffect(onDotEffect); getChildren().add(dots); // update digits to current time and start timer to update every second refreshClocks(); }
Example #22
Source File: TimelineSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public TimelineSample() { super(280,120); //create a circle final Circle circle = new Circle(25,25, 20, Color.web("1c89f4")); circle.setEffect(new Lighting()); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can start/pause/stop/play animation by //timeline.play(); //timeline.pause(); //timeline.stop(); //timeline.playFromStart(); //add the following keyframes to the timeline timeline.getKeyFrames().addAll (new KeyFrame(Duration.ZERO, new KeyValue(circle.translateXProperty(), 0)), new KeyFrame(new Duration(4000), new KeyValue(circle.translateXProperty(), 205))); getChildren().add(createNavigation()); getChildren().add(circle); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Timeline rate", timeline.rateProperty(), -4d, 4d) //TODO it is possible to do it for integer? ); // END REMOVE ME }
Example #23
Source File: CarPane.java From Intro-to-Java-Programming with MIT License | 5 votes |
/** Create a car an place it in the pane */ private void drawCar() { getChildren().clear(); rectangle = new Rectangle(x, y - 20, 50, 10); polygon = new Polygon(x + 10, y - 20, x + 20, y - 30, x + 30, y - 30, x + 40, y - 20); circle1 = new Circle(x + 15, y - 5, radius); circle2 = new Circle(x + 35, y - 5, radius); getChildren().addAll(rectangle, circle1, circle2, polygon); }
Example #24
Source File: StopWatch.java From netbeans with Apache License 2.0 | 5 votes |
private void configureBackground() { ImageView imageView = new ImageView(); Image image = loadImage(); imageView.setImage(image); Circle circle1 = new Circle(); circle1.setCenterX(140); circle1.setCenterY(140); circle1.setRadius(120); circle1.setFill(Color.TRANSPARENT); circle1.setStroke(Color.web("#0A0A0A")); circle1.setStrokeWidth(0.3); Circle circle2 = new Circle(); circle2.setCenterX(140); circle2.setCenterY(140); circle2.setRadius(118); circle2.setFill(Color.TRANSPARENT); circle2.setStroke(Color.web("#0A0A0A")); circle2.setStrokeWidth(0.3); Circle circle3 = new Circle(); circle3.setCenterX(140); circle3.setCenterY(140); circle3.setRadius(140); circle3.setFill(Color.TRANSPARENT); circle3.setStroke(Color.web("#818a89")); circle3.setStrokeWidth(1); Ellipse ellipse = new Ellipse(140, 95, 180, 95); Circle ellipseClip = new Circle(140, 140, 140); ellipse.setFill(Color.web("#535450")); ellipse.setStrokeWidth(0); GaussianBlur ellipseEffect = new GaussianBlur(); ellipseEffect.setRadius(10); ellipse.setEffect(ellipseEffect); ellipse.setOpacity(0.1); ellipse.setClip(ellipseClip); background.getChildren().addAll(imageView, circle1, circle2, circle3, ellipse); }
Example #25
Source File: StopWatch.java From netbeans with Apache License 2.0 | 5 votes |
private void configureHand() { Circle circle = new Circle(0, 0, radius / 18); circle.setFill(color); Rectangle rectangle1 = new Rectangle(-0.5 - radius / 140, +radius / 7 - radius / 1.08, radius / 70 + 1, radius / 1.08); Rectangle rectangle2 = new Rectangle(-0.5 - radius / 140, +radius / 3.5 - radius / 7, radius / 70 + 1, radius / 7); rectangle1.setFill(color); rectangle2.setFill(Color.BLACK); hand.getChildren().addAll(circle, rectangle1, rectangle2); }
Example #26
Source File: TaskProgressIndicatorSkin.java From archivo with GNU General Public License v3.0 | 5 votes |
public DeterminateIndicator(ProgressIndicator control, Paint fillOverride) { getStyleClass().add("determinate-indicator"); degProgress = (int) (360 * control.getProgress()); getChildren().clear(); // The circular background for the progress pie piece indicator = new StackPane(); indicator.setScaleShape(false); indicator.setCenterShape(false); indicator.getStyleClass().setAll("indicator"); indicatorCircle = new Circle(); indicator.setShape(indicatorCircle); // The shape for our progress pie piece arcShape = new Arc(); arcShape.setType(ArcType.ROUND); arcShape.setStartAngle(90.0F); // Our progress pie piece progress = new StackPane(); progress.getStyleClass().setAll("progress"); progress.setScaleShape(false); progress.setCenterShape(false); progress.setShape(arcShape); progress.getChildren().clear(); setFillOverride(fillOverride); // The check mark that's drawn at 100% tick = new StackPane(); tick.getStyleClass().setAll("tick"); getChildren().setAll(indicator, progress, tick); updateProgress(control.getProgress()); }
Example #27
Source File: SmoothAreaChartTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
private void drawDataPoint(final double X, final double Y, final Color COLOR) { double radius = size * 0.02; Circle circle = new Circle(X, Y, radius); circle.setStroke(tile.getBackgroundColor()); circle.setFill(COLOR); circle.setStrokeWidth(size * 0.01); dataPointGroup.getChildren().add(circle); }
Example #28
Source File: Exercise_15_16.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create two circles Circle circle1 = new Circle(40, 40, 10); setProperties(circle1); Circle circle2 = new Circle(120, 150, 10); setProperties(circle2); // Place nodes in pane pane.getChildren().addAll(getLine(circle1, circle2), circle1, circle2, getText(circle1, circle2)); // Create and register the handle pane.setOnMouseDragged(e -> { if (circle1.contains(e.getX(), e.getY())) { pane.getChildren().clear(); circle1.setCenterX(e.getX()); circle1.setCenterY(e.getY()); pane.getChildren().addAll(getLine(circle1, circle2), circle1, circle2, getText(circle1, circle2)); } else if (circle2.contains(e.getX(), e.getY())) { pane.getChildren().clear(); circle2.setCenterX(e.getX()); circle2.setCenterY(e.getY()); pane.getChildren().addAll(getLine(circle1, circle2), circle1, circle2, getText(circle1, circle2)); } }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_15_16"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example #29
Source File: Exercise_15_20.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create three points and add them to a list Circle p1 = new Circle(50, 100, 5); Circle p2 = new Circle(100, 25, 5); Circle p3 = new Circle(150, 80, 5); ArrayList<Circle> points = new ArrayList<>(); points.add(p1); points.add(p2); points.add(p3); // Place nodes in the pane drawTriangle(pane, points); pane.getChildren().addAll(p1, p2, p3); placeText(pane, points); // Create and register the handle pane.setOnMouseDragged(e -> { for (int i = 0; i < points.size(); i++) { if (points.get(i).contains(e.getX(), e.getY())) { pane.getChildren().clear(); points.get(i).setCenterX(e.getX()); points.get(i).setCenterY(e.getY()); drawTriangle(pane, points); pane.getChildren().addAll(p1, p2, p3); placeText(pane, points); } } }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_15_20"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example #30
Source File: JFXTimePickerContent.java From JFoenix with Apache License 2.0 | 5 votes |
private StackPane createMinutesContent(LocalTime time) { // create minutes content StackPane minsPointer = new StackPane(); Circle selectionCircle = new Circle(contentCircleRadius / 6); selectionCircle.fillProperty().bind(timePicker.defaultColorProperty()); Circle minCircle = new Circle(selectionCircle.getRadius() / 8); minCircle.setFill(Color.rgb(255, 255, 255, 0.87)); minCircle.setTranslateX(selectionCircle.getRadius() - minCircle.getRadius()); minCircle.setVisible(time.getMinute() % 5 != 0); selectedMinLabel.textProperty().addListener((o, oldVal, newVal) -> { if (Integer.parseInt(newVal) % 5 == 0) { minCircle.setVisible(false); } else { minCircle.setVisible(true); } }); double shift = 9; Line line = new Line(shift, 0, contentCircleRadius, 0); line.fillProperty().bind(timePicker.defaultColorProperty()); line.strokeProperty().bind(line.fillProperty()); line.setStrokeWidth(1.5); minsPointer.getChildren().addAll(line, selectionCircle, minCircle); StackPane.setAlignment(selectionCircle, Pos.CENTER_LEFT); StackPane.setAlignment(minCircle, Pos.CENTER_LEFT); Group pointerGroup = new Group(); pointerGroup.getChildren().add(minsPointer); pointerGroup.setTranslateX((-contentCircleRadius + shift) / 2); minsPointerRotate = new Rotate(0, contentCircleRadius - shift, selectionCircle.getRadius()); pointerGroup.getTransforms().add(minsPointerRotate); Pane clockLabelsContainer = new Pane(); // inner circle radius double radius = contentCircleRadius - shift - selectionCircle.getRadius(); for (int i = 0; i < 12; i++) { StackPane labelContainer = new StackPane(); int val = ((i + 3) * 5) % 60; Label label = new Label(String.valueOf(unitConverter.toString(val))); label.setFont(Font.font(ROBOTO, FontWeight.BOLD, 12)); // init label color label.setTextFill(val == time.getMinute() ? Color.rgb(255, 255, 255, 0.87) : Color.rgb(0, 0, 0, 0.87)); selectedMinLabel.textProperty().addListener((o, oldVal, newVal) -> { if (Integer.parseInt(newVal) == Integer.parseInt(label.getText())) { label.setTextFill(Color.rgb(255, 255, 255, 0.87)); } else { label.setTextFill(Color.rgb(0, 0, 0, 0.87)); } }); labelContainer.getChildren().add(label); double labelSize = (selectionCircle.getRadius() / Math.sqrt(2)) * 2; labelContainer.setMinSize(labelSize, labelSize); double angle = 2 * i * Math.PI / 12; double xOffset = radius * Math.cos(angle); double yOffset = radius * Math.sin(angle); final double startx = contentCircleRadius + xOffset; final double starty = contentCircleRadius + yOffset; labelContainer.setLayoutX(startx - labelContainer.getMinWidth() / 2); labelContainer.setLayoutY(starty - labelContainer.getMinHeight() / 2); // add label to the parent node clockLabelsContainer.getChildren().add(labelContainer); } minsPointerRotate.setAngle(180 + (time.getMinute() + 45) % 60 * Math.toDegrees(2 * Math.PI / 60)); return new StackPane(pointerGroup, clockLabelsContainer); }