Table of contents
1.
Introduction
2.
ImageInput Class
3.
Constructors
4.
Properties and their Corresponding Setter Methods
5.
Implementation
6.
Frequently Asked Questions
6.1.
Which JDK has JavaFX?
6.2.
Is JavaFX different from Java?
6.3.
What is replacing JavaFX?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

JavaFX ImageInput

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Adding images of our choice to our favorite graphics is a fascinating task don’t you think? But most of us find the how part more difficult. Don’t worry young ninjas! We had you cover, we are going to introduce you to JavaFX imageinput class using which you can add images to the graphics of your choice. Before going further, let’s know a little about JavaFX.

JavaFX is a Java library for creating rich client applications. It provides an API for creating graphical user interface (GUI) applications that can run on almost any device that supports Java.

 

This blog will discuss the ImageInput class present in the JavaFX framework. We will also examine the types of constructors and methods present in the ImageInput class. Along with its implementation, so let’s get started.

ImageInput Class

The ImageInput class is used in the JavaFX application to apply various image input effects. In JavaFX, the image input effect simply embeds an image into the JavaFX screen. It is used to pass the specified colored rectangular region as an input to another effect, just like the Color Input effect. It can fill the specified shape with a given image input effect.

An Image Input effect is used to pass the specified image into another effect. This effect is primarily used to pass the unmodified image into the other effects. 

The methods that we are going to need are present in the javafx.scene.effect class.

Constructors

There are three different types of constructors available in the imageinput class:

  1. ImageInput(): Initializes the ImageInput class with the default parameters.
  2. ImageInput(Image source): Create an instance of ImageInput with the specified image source.
  3. ImageInput(Image source, Double X, Double Y): Create an ImageInput object with the default image source and the specified coordinates.

Properties and their Corresponding Setter Methods

Javafx.scene.effect.ImageInput class properties and their setter methods are described in the table below.

Properties and methods

Implementation

import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.effect.ImageInput; 
import javafx.scene.image.Image; 
import javafx.scene.shape.Rectangle; 
import javafx.stage.Stage; 
         
public class ImageInputEffectExample extends Application { 
   @Override  
   public void start(Stage stage) {       
      //Creating an image 
      Image image = new Image("https://www.codingninjas.com/blog/wp-content/uploads/2020/04/LOGO-05.png"); 
             
      //Instantiating the Rectangle class 
      Rectangle rectangle = new Rectangle(); 
     
      //Instantiating the ImageInput class 
      ImageInput imageInput = new ImageInput(); 
      
      //Setting the position of the image
      imageInput.setX(150); 
      imageInput.setY(100);       
      
      //Setting source for image input  
      imageInput.setSource(image); 
       
      //Applying image input effect to the rectangle node 
      rectangle.setEffect(imageInput);    
         
      //Creating a Group object  
      Group root = new Group(rectangle);   
               
      //Creating a scene object 
      Scene scene = new Scene(root, 600, 300);  
      
      //Setting title to the Stage 
      stage.setTitle("Sample Application"); 
         
      //Adding scene to the stage 
      stage.setScene(scene); 
         
      //Displaying the contents of the stage 
      stage.show();         
   } 
   public static void main(String args[]){ 
      launch(args); 
   } 
}

 

Output

Output

Frequently Asked Questions

Which JDK has JavaFX?

The JavaFX SDK and runtime are included in the JDK, starting with Java SE 7 Update 2.

Is JavaFX different from Java?

The JavaFX is actually a different language than Java (similar, but different syntax), but it runs on a JVM and can use Java classes. It is mainly developed for "RIA" (rich Internet applications) across a variety of devices.

What is replacing JavaFX?

GWT, Vaadin, Qt, JSF, and Electron are some most popular alternatives and competitors of JavaFX.

Conclusion

In this article, we have extensively discussed the ImageInput class present inside JavaFX Framework. We have seen different constructors initialized in ImageInput class. Also, we have seen different methods available inside the class along with the implementation.

If you think this blog has helped you enhance your knowledge about JavaFx ImageInput and if you would like to learn more, check out our articles JavaFXIntroduction to JavaFX effectsJavaFX FlowPaneJavaFX StackPaneJavaFX GridPaneJavaFX Rotate Transition, and many more on our Website.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem 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 suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Happy Learning!

Live masterclass