Found 2616 Articles for Java

Explain the Intersect operation on 2D shapes in JavaFX

Maruthi Krishna
Updated on 14-Apr-2020 07:12:45

609 Views

This operation takes two or more shapes as inputs and returns the intersection area between them as shown below.The intersect() (static) method of the javafx.scene.shape.Shape class accepts two Shape objects and returns the result of the intersect operation of the given objects.Exampleimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.Circle; import javafx.scene.shape.Shape; public class JavaFXIntersectExample extends Application {    public void start(Stage stage) {       //Drawing circle1       Circle circle1 = new Circle();       circle1.setCenterX(230.0f);       circle1.setCenterY(100.0f);       circle1.setRadius(75.0f);       circle1.setFill(Color.DARKRED);       //Drawing ... Read More

Explain the Union operation on 2D shapes in JavaFX

Maruthi Krishna
Updated on 14-Apr-2020 07:10:06

229 Views

This operation takes two or more shapes as inputs and returns the area occupied by them combined as shown below.The union() (static) method of the javafx.scene.shape.Shape class accepts two Shape objects and returns the result of the union operation of the given objects.Exampleimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.Circle; import javafx.scene.shape.Shape; public class JavaFXUnionExample extends Application {    public void start(Stage stage) {       //Drawing circle1       Circle circle1 = new Circle();       circle1.setCenterX(230.0f);       circle1.setCenterY(100.0f);       circle1.setRadius(75.0f);       circle1.setFill(Color.DARKRED);       ... Read More

What are various operations of 2D objects in JavaFX?

Maruthi Krishna
Updated on 14-Apr-2020 07:07:36

71 Views

JavaFX supports three operations on 2D objects namely – Union, Subtraction and Intersection.Union Operation − This operation takes two or more shapes as inputs and returns the area occupied by them.Intersection Operation − This operation takes two or more shapes as inputs and returns the intersection area between them.Subtraction Operation − This operation takes two or more shapes as an input. Then, it returns the area of the first shape excluding the area overlapped by the second one.Exampleimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.Circle; import javafx.scene.shape.Shape; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; public ... Read More

How to draw custom shapes in JavaFX using the Path class?

Maruthi Krishna
Updated on 14-Apr-2020 07:03:59

449 Views

The javafx.scene.shape package provides classes using which you can draw various 2D shapes, but these are just primitive shapes like line, circle, polygon, and ellipse, etc…Therefore, if you want to draw complex custom shapes you need to use the Path class.The Path ClassThe Path class represents the geometrical outline of a shape and is attached to an observable list which holds various Path Elements such as MoveTo, LineTo, HlineTo, VlineTo, ArcTo, QuadCurveTo, CubicCurveTo.The constructor of this class accepts variable arguments of the type PathElement and constructs a path based on the given path elements.ExampleThe Path Element MoveTo is used to move ... Read More

What are various 2D shapes provided by JavaFX?

Maruthi Krishna
Updated on 14-Apr-2020 07:01:49

144 Views

Following are various geometrical shapes that you can draw using JavaFXLine − A line is a geometrical structure joining two-point. The javafx.scene.shape.The line class represents a line in the XY plane.Rectangle − A rectangle is a four-sided polygon that has two pairs of parallel and concurrent sides with all interior angles as right angles. The javafx.scene.The Rectangle class represents a rectangle in the XY plane.Circle − A circle is a line forming a closed loop, every point on which is a fixed distance from a center point. The javafx.scene.The Circle class represents a circle in the XY plane.Ellipse − An ... Read More

How can we customize the start of JShell in Java 9?

raja
Updated on 13-Apr-2020 17:42:19

137 Views

JShell is an interactive REPL tool to execute and evaluate simple Java programs like variable declarations, statements, expressions, and etc.When the JShell tool launched, the code has pre-loaded by default. To display this code, we just launch the command "/list -start". It is possible to ask JShell to load them automatically when it starts by using the command: "/set start [-retain] [Type]". The first option "-retain" tells JShell to record the desired [Type] startup for the next JShell sessions. If we don't specify it, the default startup can be launched when opening a new session  /set start [-retain] -File   /set start ... Read More

How can we implement the Subscriber interface in Java 9?

raja
Updated on 13-Apr-2020 13:51:04

624 Views

Java 9 supports to create Reactive Streams by introducing a few interfaces: Publisher, Subscriber, Subscription, and SubmissionPublisher class that implements the Publisher interface. Each interface can play a different role corresponding to the principles of Reactive Streams.We can use the Subscriber interface to subscribe to the data that is being published by a publisher. We need to implement the Subscriber interface and provide an implementation for the abstract methods.Flow.Subscriber interface methods:onComplete(): This method has been called when the Publisher object completes its role.onError(): This method has been called when something goes wrong in Publisher and is notified to the Subscriber.onNext(): This method has been called whenever ... Read More

How to draw a geometrical 2D shape in JavaFX?

Maruthi Krishna
Updated on 13-Apr-2020 12:17:13

179 Views

In general, a 2D shape is a geometrical figure that can be drawn on the XY plane, these include Line, Rectangle, Circle, etc.The javafx.scene.shape package provides you, various classes, each of them represents/defines a 2d geometrical object or, an operation on them. The class named Shape is the base class of all the 2-Dimensional shapes in JavaFX.Creating 2D shapesTo draw a 2D geometrical shape using JavaFX you need to −Instantiate the class − Instantiate the respective class. For example, if you want to draw a circle you need to instantiate the Circle class as shown below −//Drawing a Circle Circle ... Read More

How to Create the path element arc in JavaFX?

Maruthi Krishna
Updated on 13-Apr-2020 12:14:22

171 Views

This is class represents the path element arc. It helps you to draw an arc from the current coordinates to the specified (new) coordinates.To create a line path element −Instantiate the ArcTo class.Set values to the properties of this class using setter methods or, bypassing them to the constructor.Instantiate the Path class.Get the observable list object of the above-created Path using the getElements() method.Add the above created ArcTo object to the observable list using the add() method.Finally, add the path to the Group object.Exampleimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.ArcTo; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import ... Read More

How to Create the path element cubic curve in JavaFX?

Maruthi Krishna
Updated on 13-Apr-2020 12:12:27

181 Views

This is class represents the path element cubic curve. It helps you to draw a cubic curve form the current coordinates to the specified (new) coordinates.To create a line path element −Instantiate the CubicCurve class.Set values to the properties of this class using setter methods or, bypassing them to the constructor.Instantiate the Path class.Get the observable list object of the above-created Path using the getElements() method.Add the above created CubicCurve object to the observable list using the add() method.Finally, add the path to the Group object.Exampleimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.CubicCurveTo; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; ... Read More

Advertisements