Javafx-color-input-effect

提供:Dev Guides
移動先:案内検索

JavaFXエフェクト-カラー入力

カラー入力エフェクトは、長方形を描画して色で塗りつぶすのと同じ出力を提供します。 他のエフェクトとは異なり、このエフェクトをノードに適用すると、ノードではなく長方形のボックスのみが表示されます。 このエフェクトは、主に他のエフェクトの入力として渡すために使用されます。

たとえば、ブレンドエフェクトを適用する場合、入力としてエフェクトタイプのオブジェクトが必要です。 そこで、これを入力として渡すことができます。

パッケージ javafx.scene.effectColorInput という名前のクラスは、色の入力効果を表します。 このクラスには4つのプロパティが含まれています-

  • x -このプロパティはdouble型です。色入力の位置のx座標を表します。
  • y -このプロパティはdouble型です。カラー入力の位置のy座標を表します。
  • 高さ-このプロパティはダブルタイプです。色で塗りつぶされる領域の高さを表します。
  • -このプロパティはダブルタイプです。色で塗りつぶされる領域の幅を表します。
  • paint -このプロパティはPaintタイプです。入力領域を塗りつぶす色を表します。

以下は、カラー入力効果を示す例です。 ここでは、位置50、140で寸法50、400(高さ、幅)のカラー入力を作成し、それに色CHOCOLATEを入力しています。

四角形を作成し、この効果を適用しています。 このコードを* ColorInputEffectExample.java。*という名前のファイルに保存します

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.ColorInput;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class ColorInputEffectExample extends Application {
   @Override
   public void start(Stage stage) {
     //creating a rectangle
      Rectangle rectangle = new Rectangle();

     //Instantiating the Colorinput class
      ColorInput colorInput = new ColorInput();

     //Setting the coordinates of the color input
      colorInput.setX(50);
      colorInput.setY(140);

     //Setting the height of the region of the collor input
      colorInput.setHeight(50);

     //Setting the width of the region of the color input
      colorInput.setWidth(400);

     //Setting the color the color input
      colorInput.setPaint(Color.CHOCOLATE);

     //Applying coloradjust effect to the Rectangle
      rectangle.setEffect(colorInput);

     //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);
   }
}

次のコマンドを使用して、コマンドプロンプトから保存したJavaファイルをコンパイルして実行します。

javac ColorInputEffectExample.java
java ColorInputEffectExample

実行時に、上記のプログラムは以下に示すようにJavaFXウィンドウを生成します。

カラー入力効果