>  기사  >  Java  >  JavaFX의 텍스트 노드에 흐림 효과를 추가하는 방법은 무엇입니까?

JavaFX의 텍스트 노드에 흐림 효과를 추가하는 방법은 무엇입니까?

王林
王林앞으로
2023-08-19 12:05:341470검색

setEffect() 메서드를 사용하여 JavaFX의 모든 노드 객체에 효과를 추가할 수 있습니다. 이 메소드는 Effect 클래스의 객체를 받아 현재 노드에 추가합니다.

javafx.scene.효과.GaussianBlur.GaussianBlur 클래스는 내부적으로 가우시안 컨볼루션 커널을 사용하여 흐림 효과를 나타냅니다. 따라서 텍스트 노드에 흐림 효과를 추가하려면:

  • 기본 x, y 좌표(위치)와 텍스트 문자열을 생성자에 인수로 전달하여 Text 클래스를 인스턴스화합니다.

  • 글꼴, 획 등 필수 속성을 설정합니다.

  • GaussianBlur 클래스를 인스턴스화하여 흐림 효과를 만듭니다.

  • 생성된 효과를 텍스트 노드에 설정하려면 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);
   }
}

output

JavaFX의 텍스트 노드에 흐림 효과를 추가하는 방법은 무엇입니까?

위 내용은 JavaFX의 텍스트 노드에 흐림 효과를 추가하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제