VLineTo类是JavaFX的一部分。VLineTo类创建从当前位置到指定Y坐标的垂直线路径。VLineTo类继承PathElement类。
null
类的构造函数:
- VLineTo() :创建VLineTo的空对象。
- VLineTo(双y) :创建具有指定y坐标值的VLineTo对象。
常用方法:
方法 | 解释 |
---|---|
getY() | 返回Y坐标的值。 |
赛蒂(双v) | 设置Y坐标的值。 |
toString() | 返回VLineTo对象的字符串表示形式。 |
yProperty() | 定义Y坐标。 |
以下程序说明了VLineTo类的使用:
- Java程序,用于创建路径并向其添加VLineTo并显示:
- 在这个程序中,我们将创建一个名为 路径 .
- 创建具有指定Y坐标的VLineTo对象。
- 然后创建一个名为 移动到 并添加 移动到 和 弗拉内托 对象指向路径。
- 将此路径添加到“组对象”,将“组对象”添加到场景,并将场景添加到舞台。
- 打电话给 show() 函数来显示最终结果。
// Java program to create a path
// and add VLineTo to it and display it
import
javafx.application.Application;
import
javafx.scene.Scene;
import
javafx.scene.control.*;
import
javafx.scene.layout.*;
import
javafx.stage.Stage;
import
javafx.scene.layout.*;
import
javafx.scene.paint.*;
import
javafx.scene.text.*;
import
javafx.geometry.*;
import
javafx.scene.layout.*;
import
javafx.scene.shape.*;
import
javafx.scene.paint.*;
import
javafx.scene.*;
public
class
VLineTo_1
extends
Application {
// launch the application
public
void
start(Stage stage)
{
try
{
// set title for the stage
stage.setTitle(
"VLineTo"
);
// create VLineTo
VLineTo vlineto =
new
VLineTo(
200
);
// create moveto
MoveTo moveto =
new
MoveTo(
100
,
100
);
// create a Path
Path path =
new
Path(moveto, vlineto);
// set fill for path
path.setFill(Color.BLACK);
// set stroke width
path.setStrokeWidth(
2
);
// create a Group
Group group =
new
Group(path);
// create a scene
Scene scene =
new
Scene(group,
400
,
300
);
// set the scene
stage.setScene(scene);
stage.show();
}
catch
(Exception e) {
System.out.println(e.getMessage());
}
}
// Main Method
public
static
void
main(String args[])
{
// launch the application
launch(args);
}
}
输出:
- Java程序,用于创建路径并向其添加多个VLineTo对象并显示:
- 在这个程序中,我们将创建一个名为 路径 .
- 使用指定的Y坐标创建三个VLineTo对象。
- 然后创建三个MoveTo对象,名为 移动到 , 移动到_1 和 移动到_2 .
- 加上所有 移动到 和 弗拉内托 对象按顺序指向路径。
- 将此路径添加到“组对象”,将“组对象”添加到场景,并将场景添加到舞台。
- 打电话给 show() 函数来显示最终结果。
// Java program to create a path and add the
// multiple VLineTo object to it and display it
import
javafx.application.Application;
import
javafx.scene.Scene;
import
javafx.scene.control.*;
import
javafx.scene.layout.*;
import
javafx.stage.Stage;
import
javafx.scene.layout.*;
import
javafx.scene.paint.*;
import
javafx.scene.text.*;
import
javafx.geometry.*;
import
javafx.scene.layout.*;
import
javafx.scene.shape.*;
import
javafx.scene.paint.*;
import
javafx.scene.*;
public
class
VLineTo_2
extends
Application {
// launch the application
public
void
start(Stage stage)
{
try
{
// set title for the stage
stage.setTitle(
"VLineTo"
);
// create VLineTo
VLineTo vlineto =
new
VLineTo(
200
);
VLineTo vlineto_1 =
new
VLineTo(
250
);
VLineTo vlineto_2 =
new
VLineTo(
225
);
// create moveto
MoveTo moveto =
new
MoveTo(
100
,
100
);
MoveTo moveto_1 =
new
MoveTo(
200
,
100
);
MoveTo moveto_2 =
new
MoveTo(
300
,
100
);
// create a Path
Path path =
new
Path(moveto, vlineto, moveto_1,
vlineto_1, moveto_2, vlineto_2);
// set fill for path
path.setFill(Color.BLACK);
// set stroke width
path.setStrokeWidth(
2
);
// create a Group
Group group =
new
Group(path);
// create a scene
Scene scene =
new
Scene(group,
400
,
300
);
// set the scene
stage.setScene(scene);
stage.show();
}
catch
(Exception e) {
System.out.println(e.getMessage());
}
}
// Main Method
public
static
void
main(String args[])
{
// launch the application
launch(args);
}
}
输出:
注: 以上程序可能无法在联机IDE中运行,请使用脱机编译器。
参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/VLineTo.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END