Implementation
Let's now examine the lighting class's real implementation.
Background
The application below retrieves the image from the specified URL, loads it, and then attaches it to two distinct imageView instances. after making a few adjustments to the image, such as changing the height and positioning. The lighting object is made, and then we set the light source for it. After that, the second imageView object is given this lighting effect. Then, we create two distinct text objects that display the image's description underneath them. Finally, we combine all of these nodes into a scene, give it a title, and invoke the show function to display the results.
Program
// importing required libraries
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Lighting;
import javafx.scene.effect.Light.Distant;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;
public class Lighting_Example extends Application {
@Override
public void start(Stage stage) throws Exception {
// loading the image
Image image = new Image("https://files.codingninjas.in/cn-17917.png");
// imageview to display above image
ImageView imageView = new ImageView(image);
ImageView imageView2 = new ImageView(image);
// setting position of both the images
imageView.setX(50);
imageView.setY(60);
imageView2.setX(350);
imageView2.setY(60);
// setting the size of both the images
imageView.setFitHeight(200);
imageView.setFitWidth(200);
imageView2.setFitHeight(200);
imageView2.setFitWidth(200);
// preserve ratio of the image
imageView.setPreserveRatio(true);
imageView2.setPreserveRatio(true);
// light source
Distant source = new Distant();
// setting properties for our light source
source.setAzimuth(0.6);
source.setColor(Color.ORANGE);
// creating and setting the lighting effect
Lighting lighting = new Lighting();
imageView2.setEffect(lighting);
// setting the light source
lighting.setLight(source);
// text displayed below the first image
Text text = new Text();
text.setFont(Font.font(null, FontWeight.BOLD, 15));
text.setX(50);
text.setY(290);
text.setText("Without Lighting Effect");
text.setFill(Color.RED);
// text displayed below second image
Text text2 = new Text();
text2.setFont(Font.font(null, FontWeight.BOLD, 15));
text2.setX(370);
text2.setY(290);
text2.setText("With Lighting Effect");
text2.setFill(Color.RED);
// grouping all the nodes together
Group group = new Group(imageView, imageView2, text, text2);
/// creating scene
Scene scene = new Scene(group, 600, 350);
// setting scene
stage.setScene(scene);
// setting the title for our stage
stage.setTitle("Lighting Example");
// displaying the result
stage.show();
}
public static void main(String[] args) {
// launching the application
launch(args);
}
}

You can also try this code with Online Java Compiler
Run Code
How to execute the above program?
To execute the above program. You can follow the given steps:
-
Open the terminal in the same folder where you have saved your source code.
-
Enter the below code and hit enter.
javac --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
After you hit enter a new file will automatically be generated namely yourFilename.class
-
Now, enter the below command and hit enter to execute the above program.
java --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
-
You have successfully executed the JavaFX program.
Output

Frequently Asked Questions
What is the difference between JavaFX Light.Distant and JavaFX Light.Point?
In JavaFX Light.Distant class the light source is kept at a fair distance from the object whereas in JavaFX Light.Point the light source is more focussed on a point of an object.
Why do the lighting effects get dimmer when we use JavaFX Light.Distant effect?
It happens because we are assuming that the light source is kept far away from the source hence to match the visualization the light gets attenuated and eventually becomes dimmer.
What properties do JavaFX Light.Distant have?
It has two properties named azimuth and elevation. Both of them are of double type.
Conclusion
In this article, we have extensively discussed the JavaFX light.distant class available in JavaFx Framework. We have also seen the implementation of JavaFX light.distant and we can use this JavaFX light.distant light source into our program.
If you think this blog has helped you enhance your knowledge about JavaFx light.Distant light source and if you would like to learn more, check out our articles JavaFX, JavaFX HBox, JavaFX FileChooser, JavaFX VBox, JavaFX Fade Transition, JavaFX Sequential Transition, and many more on our Website.
Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problems, interview experiences, and interview bundle for placement preparations.
Nevertheless, you may consider our paid courses to give your career an edge over others!

Please upvote our blog to help other ninjas grow.
Happy Learning!