আপনি setEffect() ব্যবহার করে JavaFX-এর যেকোনো নোড অবজেক্টে একটি প্রভাব যোগ করতে পারেন পদ্ধতি এই পদ্ধতিটি প্রভাব এর একটি বস্তু গ্রহণ করে ক্লাস এবং বর্তমান নোডে যোগ করে।
javafx.scene.effect.GaussianBlur.GaussianBlur ক্লাস একটি অস্পষ্ট প্রভাব উপস্থাপন করে যা অভ্যন্তরীণভাবে গাউসিয়ান কনভোলিউশন কার্নেল ব্যবহার করে। অতএব, একটি টেক্সট নোডে একটি অস্পষ্ট প্রভাব যোগ করতে -
-
কন্সট্রাক্টরের আর্গুমেন্ট হিসেবে x,y কোঅর্ডিনেট (অবস্থান) এবং টেক্সট স্ট্রিংকে বাইপাস করে টেক্সট ক্লাস ইনস্ট্যান্ট করুন।
-
ফন্ট, স্টোক, ইত্যাদির মতো পছন্দসই বৈশিষ্ট্যগুলি সেট করুন।
-
Gaussian Blur ইনস্ট্যান্টিয়েট করে একটি অস্পষ্ট প্রভাব তৈরি করুন ক্লাস।
-
setEffect() ব্যবহার করে টেক্সট নোডে তৈরি করা প্রভাব সেট করুন পদ্ধতি।
-
অবশেষে, গ্রুপ অবজেক্টে তৈরি করা টেক্সট নোড যোগ করুন।
উদাহরণ
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class TextBlurEffect extends Application {
public void start(Stage stage) throws FileNotFoundException {
//Creating a text object
String str = "Welcome to Tutorialspoint";
Text text = new Text(30.0, 80.0, str);
//Setting the font
Font font = Font.font("Brush Script MT", FontWeight.BOLD,
FontPosture.REGULAR, 65);
text.setFont(font);
//Setting the color of the text
text.setFill(Color.BROWN);
//Setting the width and color of the stroke
text.setStrokeWidth(2);
text.setStroke(Color.BLUE);
//Setting the blur effect to the text
GaussianBlur blur = new GaussianBlur();
text.setEffect(blur);
//Setting the stage
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Blur Effect");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} আউটপুট
