JavaFX | Light.Point Class

Light.Point class is a part of JavaFX. Light.Point class represents a point light source in 3D space. Light.Point class extends the Light class.
Constructors of the class:
- Point(): Creates a new Point Light object with default values.
- Point(double x, double y, double z, Color color): Creates a new Point Light object with x, y, z and color values.
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getX() | Returns the value of x. |
| getY() | Returns the value of y. |
| getZ() | Returns the value of z. |
| setX(double v) | Sets the value of x. |
| setY(double v) | Sets the value of y. |
| setZ(double v) | Sets the value of z. |
| getColor() | Returns the color of light. |
| setColor(Color v) | Sets the color of light. |
Below programs illustrate the use of Light.point class:
- Java Program to create a Point light and add it to a rectangle: In this program we will create a Rectangle named rectangle with specified height and width. We will also create a Light.Point object named light. We will set the x, y, z values using setX(), setY() and setZ() function. Now create a lighting object and add the light object to lighting using setLight() function. We will set the Lighting effect to the Rectangle and add it to the scene and add the scene to the stage and call the show function to display the results.
// Java Program to create a Point light// and add it to a rectangleimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.shape.Rectangle;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.scene.Group;importjavafx.scene.effect.Light.*;importjavafx.scene.effect.*;importjavafx.scene.paint.Color;publicclassPoint_1extendsApplication {// launch the applicationpublicvoidstart(Stage stage){// set title for the stagestage.setTitle("creating Light.Point");// create point Light objectLight.Point light =newLight.Point();// set coordinateslight.setX(100);light.setY(100);light.setZ(100);// create a lightingLighting lighting =newLighting();// set Light of lightinglighting.setLight(light);// create a rectangleRectangle rect =newRectangle(250,250);// set fillrect.setFill(Color.WHITE);// set effectrect.setEffect(lighting);// create a GroupGroup group =newGroup(rect);// create a sceneScene scene =newScene(group,500,300);// set the scenestage.setScene(scene);stage.show();}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}Output:
- Java Program to create a Point light and add it to a rectangle and set the color of the light to red: In this program we will create a Rectangle named rectangle with specified height and width. We will also create a Light.Point object named light. Now pass the x, y, z and the color values as parameters of the constructor. We will create a lighting object and add the light object to lighting using setLight() function. We will set the Lighting effect to the Rectangle and add it to the scene and add the scene to the stage and call the show function to display the results.
// Java Program to create a Point light and add it to// a rectangle and set the color of the light to redimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.shape.Rectangle;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.scene.Group;importjavafx.scene.effect.Light.*;importjavafx.scene.effect.*;importjavafx.scene.paint.Color;publicclassPoint_2extendsApplication {// launch the applicationpublicvoidstart(Stage stage){// set title for the stagestage.setTitle("creating Light.Point");// create point Light objectLight.Point light =newLight.Point(100,100,100, Color.RED);// create a lightingLighting lighting =newLighting();// set Light of lightinglighting.setLight(light);// create a rectangleRectangle rect =newRectangle(250,250);// set fillrect.setFill(Color.WHITE);// set effectrect.setEffect(lighting);// create a GroupGroup group =newGroup(rect);// create a sceneScene scene =newScene(group,500,300);// set the scenestage.setScene(scene);stage.show();}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}Output:
Note: The above programs might not run in an online IDE. Please use an offline compiler.
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Light.Point.html




