PointLight is a part of JavaFX. PointLight defines a point light source. PointLight is a fixed light source in space that radiates light in all direction.
Constructor of the class are:
- PointLight(): Creates a new instance of pointlight
- PointLight(Color c): Creates a new instance of point light of specific color
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getColor() | returns the color of the light |
| isLightOn() | returns whether the light is on or not |
| setColor(Color value) | sets the color of the light |
| setLightOn(boolean value) | Sets the value of the property lightOn. |
Below programs illustrate the PointLight class:
- Java program to create a point light of default color: This program creates a Sphere indicated by the name sphere(radius is passed as arguments). A PointLight is created named pointlight which is a point light source and radiates light in all direction. The Sphere will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the sphere and pointlight are attached. The group is attached to the scene. Finally, the show() method is called to display the final results. A perspective camera will be created and added to the scene to render the cylinder in 3D.
// Java program to create a point light of default colorimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.shape.DrawMode;importjavafx.scene.layout.*;importjavafx.event.ActionEvent;importjavafx.scene.PointLight;importjavafx.scene.shape.Sphere;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.scene.Group;importjavafx.scene.PerspectiveCamera;importjavafx.scene.paint.Color;ÂÂpublicclasspointlight_2extendsApplication {   Â// launch the application   Âpublicvoidstart(Stage stage)   Â{        Â       Â// set title for the stage       Âstage.setTitle("creating sphere");       Â// create a sphere       ÂSphere sphere =newSphere(80.0f);       Â// create a point light       ÂPointLight pointlight =newPointLight();       Â// create a Group       ÂGroup group =newGroup(sphere, pointlight);       Â// translate the sphere to a position       Âsphere.setTranslateX(100);       Âsphere.setTranslateY(100);       Â// translate point light       Âpointlight.setTranslateZ(-1000);       Âpointlight.setTranslateX(+1000);       Âpointlight.setTranslateY(+10);       Â// create a perspective camera       ÂPerspectiveCamera camera =newPerspectiveCamera(false);       Âcamera.setTranslateX(0);       Âcamera.setTranslateY(0);       Âcamera.setTranslateZ(0);       Â// create a scene       ÂScene scene =newScene(group,500,300);       Âscene.setCamera(camera);       Â// 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 of a specified color(e.g. RED): This program creates a Sphere indicated by the name sphere( radius is passed as arguments). A PointLight is created named pointlight( with a specified color passed as an argument which is a point light source and radiates light in all direction. The Sphere will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the sphere and pointlight are attached. The group is attached to the scene. Finally, the show() method is called to display the final results. A perspective camera will be created and added to the scene to render the cylinder in 3D.
// Java program to create a point light// of specified color(eg RED)importjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.shape.DrawMode;importjavafx.scene.layout.*;importjavafx.event.ActionEvent;importjavafx.scene.PointLight;importjavafx.scene.shape.Sphere;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.scene.Group;importjavafx.scene.PerspectiveCamera;importjavafx.scene.paint.Color;ÂÂpublicclasssphere_1extendsApplication {   Â// launch the application   Âpublicvoidstart(Stage stage)   Â{        Â       Â// set title for the stage       Âstage.setTitle("creating sphere");       Â// create a sphere       ÂSphere sphere =newSphere(80.0f);       Â// create a point light       ÂPointLight pointlight =newPointLight(Color.RED);       Â// create a Group       ÂGroup group =newGroup(sphere, pointlight);       Â// translate the sphere to a position       Âsphere.setTranslateX(100);       Âsphere.setTranslateY(100);       Â// translate point light       Âpointlight.setTranslateZ(-1000);       Âpointlight.setTranslateX(+1000);       Âpointlight.setTranslateY(+10);       Â// create a perspective camera       ÂPerspectiveCamera camera =newPerspectiveCamera(false);       Âcamera.setTranslateX(0);       Âcamera.setTranslateY(0);       Âcamera.setTranslateZ(0);       Â// create a scene       ÂScene scene =newScene(group,500,300);       Âscene.setCamera(camera);       Â// set the scene       Âstage.setScene(scene);       Âstage.show();   Â}    Â   Â// Main Method   Âpublicstaticvoidmain(String args[])   Â{        Â       Â// launch the application       Âlaunch(args);   Â}}
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/PointLight.html

