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 application   Âpublicvoidstart(Stage stage)   Â{       Â// set title for the stage       Âstage.setTitle("creating Light.Point");       Â// create point Light object       ÂLight.Point light =newLight.Point();       Â// set coordinates       Âlight.setX(100);       Âlight.setY(100);       Âlight.setZ(100);       Â// create a lighting       ÂLighting lighting =newLighting();       Â// set Light of lighting       Âlighting.setLight(light);       Â// create a rectangle       ÂRectangle rect =newRectangle(250,250);       Â// set fill       Ârect.setFill(Color.WHITE);       Â// set effect       Ârect.setEffect(lighting);       Â// create a Group       ÂGroup group =newGroup(rect);       Â// create a scene       ÂScene scene =newScene(group,500,300);       Â// set the scene       Âstage.setScene(scene);       Âstage.show();   Â}   Â// Main Method   Âpublicstaticvoidmain(String args[])   Â{       Â// launch the application       Âlaunch(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 application   Âpublicvoidstart(Stage stage)   Â{       Â// set title for the stage       Âstage.setTitle("creating Light.Point");       Â// create point Light object       ÂLight.Point light =newLight.Point(100,100,                                    Â100, Color.RED);       Â// create a lighting       ÂLighting lighting =newLighting();       Â// set Light of lighting       Âlighting.setLight(light);       Â// create a rectangle       ÂRectangle rect =newRectangle(250,250);       Â// set fill       Ârect.setFill(Color.WHITE);       Â// set effect       Ârect.setEffect(lighting);       Â// create a Group       ÂGroup group =newGroup(rect);       Â// create a scene       ÂScene scene =newScene(group,500,300);       Â// set the scene       Âstage.setScene(scene);       Âstage.show();   Â}   Â// Main Method   Âpublicstaticvoidmain(String args[])   Â{       Â// launch the application       Âlaunch(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

