Увод у ЈаваФКС Цолор

У ЈаваФКС-у се боја може користити за попуњавање различитих облика као што су правоугаоник, елипса, круг, итд. Помоћу различитих метода могуће је направити наше нијансе боје. Једном када је направљен, може се прослиједити објекту боје у методу сетФилл (). У овом документу разговараћемо о неколико техника за прављење боја.

Како створити боју у ЈаваФКС-у?

Као што је већ речено, боје се могу произвести различитим методама:

1. Коришћење назива боје

У овој методи, име боје ће се користити за креирање боје. Изводи се уз помоћ класе јавафк.сцене.паинт.Цолор где су све боје доступне као својства класе. Назив боје може се прослиједити објекту класе Паинт у методу сетФилл (). Ево примера креирања боје помоћу назива боје.

Шифра:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Shadow;
//class that extends the application class
public class JavaFXColorExample extends Application (
//application starts at this point
@Override
public void start(Stage s) (
//create a group gp
Group gp = new Group();
//set the title
s.setTitle("Color sample using color name");
//create a rectangle r1
Rectangle r1 = new Rectangle();
//set the x coordinate of rectangle r1
r1.setX(50);
//set the x coordinate of rectangle r1
r1.setY(20);
//set the width and height of rectangle r1
r1.setWidth(110);
r1.setHeight(140);
//set the color as red by passing color name
r1.setFill(Color.RED);
//set an effect
r1.setEffect(new DropShadow());
//create a rectangle r2
Rectangle r2 = new Rectangle();
//set the x coordinate of rectangle r2
r2.setX(60);
//set the x coordinate of rectangle r2
r2.setY(60);
//set the width of rectangle r2
r2.setWidth(100);
//set the height of rectangle r2
r2.setHeight(150);
//set the color as GREEN by passing color name
r2.setFill(Color.GREEN);
//set an effect
r2.setEffect(new DropShadow());
//add children to the group
gp.getChildren().add(r1);
gp.getChildren().add(r2);
//create a scene sc
Scene sc = new Scene(gp, 700, 450);
//set the scene for the stage
s.setScene(sc);
//display the results
s.show();
)
public static void main(String() args) (
launch (args);
)
)

Излаз:

2. Коришћење Веб боје

Следећи метод за креирање боја је коришћење веб боје. Овде ће се користити Цолор.веб () метода у класи јавафк.сцене.паинт.цолор где ће се пренети 2 параметра, као што су хекс вредност и боја алфа канала. Други параметар Алпха-канал је опциони параметар који означава непрозирност боје. Алпха има распон вриједности од 0, 0 до 1, 0 и такође, може бити имплицитан или експлицитан као што је приказано у наставку.

Синтакса:

//Red color and Alpha is implicit
Color.web("#ff0000")
//Red color and Alpha is explicit
Color.web("#ff0000", 1)

Шифра:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Shadow;
//class that extends the application class
public class JavaFXColorExample extends Application (
//application starts at this point
@Override
public void start(Stage s) (
//create a group gp
Group gp = new Group();
//set the title of the stage s
s.setTitle("Color sample using web color");
//create a rectangle r1
Rectangle r1 = new Rectangle();
//set the x coordinate of rectangle r1
r1.setX(50);
//set the x coordinate of rectangle r1
r1.setY(20);
//set the width of rectangle r1
r1.setWidth(100);
//set the height of rectangle r1
r1.setHeight(150);
//set the color of rectangle r1 as red by using color.web method
r1.setFill(Color. web ("#ff0000", 1));
//set an effect
r1.setEffect(new DropShadow());
//create a rectangle r2
Rectangle r2 = new Rectangle();
//set the x coordinate of rectangle r2
r2.setX(60);
//set the x coordinate of rectangle r2
r2.setY(60);
//set the width of rectangle r2
r2.setWidth(100);
//set the height of rectangle r2
r2.setHeight(150);
//set the color of rectangle r2 as black by using color.web method
r2.setFill(Color. web ("#000000", 1));
//set an effect
r2.setEffect(new DropShadow());
//add children to the group
gp.getChildren().add(r1);
gp.getChildren().add(r2);
//create a scene sc
Scene sc = new Scene(gp, 700, 450);
//set the scene for the stage
s.setScene(sc);
//display the results
s.show();
)
public static void main(String() args) (
launch(args); ))

Излаз:

3. Коришћење ХСБ боје

У ЈаваФКС-у се боја може креирати и коришћењем комбинације Хуе, Сатуратион и Бригхтнесс, која је позната и као ХСБ боја. То се врши уз помоћ класе јавафк.сцене.паинт.Цолор која се састоји од методе Цолор.хсб () која уноси 3 цела броја као што су х, с и б.

Шифра:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Shadow;
//class that extends the application class
public class JavaFXColorExample extends Application (
//application starts at this point
@Override
public void start(Stage s) (
//create a group gp
Group gp = new Group();
//set the title of the stage s
s.setTitle("Color sample using HSB");
//create a rectangle r1
Rectangle r1 = new Rectangle();
//set the x coordinate of rectangle r1
r1.setX(50);
//set the x coordinate of rectangle r1
r1.setY(20);
//set the width of rectangle r1
r1.setWidth(100);
//set the height of rectangle r1
r1.setHeight(150);
//set an effect
r1.setEffect(new DropShadow());
//add children to the group
gp.getChildren().add(r1);
//create a scene sc
Scene sc = new Scene(gp, 700, 450, Color. hsb (180, 0, 1));
//set the scene
s.setScene(sc);
//display the results
s.show();
)
public static void main(String() args) (
launch (args);
)
)

Излаз:

4. Коришћење РГБ боје

Једна од најчешћих метода за прављење боја је РГБ систем боја у коме су Црвена, Зелена и Плава 3 компоненте. То се врши уз помоћ класе јавафк.сцене.паинт.Цолор која се састоји од методе ргб () која уноси 3 цела броја р, г и б.

Шифра:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Shadow;
//class that extends the application class
public class JavaFXColorExample extends Application (
//application starts at this point
@Override
public void start(Stage s) (
//create a group gp
Group gp = new Group();
//set the title of the stage s
s.setTitle("Color sample using RGB");
//create a rectangle r
Rectangle r1 = new Rectangle();
//set the x coordinate of rectangle r1
r1.setX(50);
//set the x coordinate of rectangle r1
r1.setY(20);
//set the width and height of rectangle r1
r1.setWidth(100);
r1.setHeight(140);
r1.setFill(Color. rgb (20, 125, 10, 0.63));
//add children to the group
gp.getChildren().add(r1);
//create a scene sc
Scene sc = new Scene(gp, 700, 450);
//set the scene
s.setScene(sc);
//display the results
s.show();
)
public static void main(String() args) (
launch (args);
)
)

Излаз:

Закључак

За попуњавање облика користе се боје, а могу се радити и различитим методама. Све ове методе су обрађене у овом документу.

Препоручени чланак

Ово је водич за ЈаваФКС боју. Овде смо расправљали о стварању боје у ЈаваФКС-у користећи разне методе заједно са имплементацијом и излазом кода. такође можете да прођете кроз наше предложене чланке да бисте сазнали више -

  1. Топ 5 ЈаваФКС изгледа
  2. ЈаваФКС апликације са функцијама
  3. ЈаваФКС вс Свинг | Топ 6 поређење
  4. ЈаваФКС ознака (примери)
  5. Како креирати потврдни оквир у ЈаваФКС-у са примерима?
  6. Примери цхецкбок-а у Боотстрап-у
  7. Комплетан водич за методе ЈаваФКС ВБок-а
  8. Водич за мени у ЈаваФКС-у са примерима?

Категорија: