다음은 JavaFX를 사용하여 그릴 수 있는 다양한 기하학적 모양입니다.
-
라인 − 선은 두 점을 연결하는 기하학적 구조입니다. javafx.scene.shape .라인 클래스는 XY 평면의 선을 나타냅니다.
-
사각형 - 직사각형은 모든 내각이 직각인 두 쌍의 평행하고 평행한 변을 갖는 4변 다각형입니다. javafx.scene.사각형 클래스는 XY 평면의 직사각형을 나타냅니다.
-
원 - 원은 닫힌 루프를 형성하는 선으로, 모든 점은 중심점에서 고정된 거리에 있습니다. javafx.scene.The 서클 클래스는 XY 평면의 원을 나타냅니다.
-
타원 − 타원은 각각 초점이라고 하는 두 점으로 정의됩니다. 타원의 한 점을 찍으면 초점 점까지의 거리 합계가 일정합니다. javafx.scene.타원 class는 XY 평면의 타원을 나타냅니다.
-
다각형 - 끝에서 끝으로 연결된 다수의 동일 평면상의 선분으로 형성된 닫힌 모양을 다각형이라고 합니다. javafx.scene.Polygon 클래스는 XY 평면의 폴리곤을 나타냅니다.
-
폴리라인 - 폴리라인은 폴리라인이 끝까지 닫히지 않는다는 점을 제외하고는 폴리곤과 동일합니다. 또는 하나 이상의 선분으로 구성된 연속선입니다. javafx.scene.폴리라인 클래스는 XY 평면의 폴리라인을 나타냅니다.
-
3차 곡선 − 3차 곡선은 XY 평면의 베지어 매개변수 곡선입니다. 3차 곡선입니다. javafx.scene.CubicCurve 클래스는 XY 평면의 3차 곡선을 나타냅니다.
-
쿼드커브 − 2차 곡선은 베지어 매개변수 곡선입니다. XY 평면은 2차 곡선입니다. javafx.scene.QuadCurve 클래스는 XY 평면의 쿼드 커브를 나타냅니다.
-
호 − 호는 곡선의 일부입니다. javafx.scene.호 클래스는 XY 평면의 호를 나타냅니다.
필요한 모양을 만들려면 다음을 수행해야 합니다.
-
해당 클래스를 인스턴스화합니다.
-
속성을 설정합니다.
-
생성된 개체를 그룹에 추가합니다.
예
다음 JavaFX 예제는 사용 가능한 모든 2D 모양의 생성을 보여줍니다 -
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.scene.shape.CubicCurve;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Polyline;
import javafx.scene.shape.QuadCurve;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class JavaFXShapes extends Application {
public void start(Stage stage) {
Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
Text cirText = new Text("Circle");
cirText.setFont(font);
cirText.setX(50);
cirText.setY(130);
Text rectText = new Text("Rectangle");
rectText.setFont(font);
rectText.setX(170);
rectText.setY(130);
Text ellipseText = new Text("Ellipse");
ellipseText.setFont(font);
ellipseText.setX(310);
ellipseText.setY(130);
Text polyText = new Text("Polygon");
polyText.setFont(font);
polyText.setX(425);
polyText.setY(130);
Text lineText = new Text("Line");
lineText.setFont(font);
lineText.setX(530);
lineText.setY(130);
Text polyLineText = new Text("Poly Line");
polyLineText.setFont(font);
polyLineText.setX(40);
polyLineText.setY(260);
Text cubicCurveText = new Text("Cubic Curve");
cubicCurveText.setFont(font);
cubicCurveText.setX(140);
cubicCurveText.setY(260);
Text quadCurveText = new Text("Quad Curve");
quadCurveText.setFont(font);
quadCurveText.setX(340);
quadCurveText.setY(260);
Text arcText = new Text("Arc");
arcText.setFont(font);
arcText.setX(490);
arcText.setY(260);
//Drawing a circle
Circle circle = new Circle(75.0f, 65.0f, 40.0f );
//Drawing a Rectangle
Rectangle rect = new Rectangle(150, 30, 100, 65);
//Drawing an ellipse
Ellipse ellipse = new Ellipse(330, 60, 60, 35);
//Drawing Polygon
Polygon poly = new Polygon(410, 60, 430, 30, 470, 30, 490, 60, 470, 100, 430, 100 );
//Drawing a Line
Line line = new Line(540, 30, 540, 90);
line.setStrokeWidth(5.0);
//Drawing a Poly line
Polyline polyLine = new Polyline(25, 210, 100, 210, 50, 180, 50, 230);
polyLine.setStrokeWidth(5.0);
//Drawing a cubic curve
CubicCurve cubicCurve = new CubicCurve(150.0, 210.0, 200.0, 70.0, 200.0, 290.0, 270.0, 210.0);
//Drawing Quadratic curve
QuadCurve quadCurve = new QuadCurve(400.0, 200.0, 440.0, 250.0, 330.0, 170.0);
//Drawing an arc
Arc arc = new Arc(490, 240, 50, 80, 30, 70);
arc.setType(ArcType.ROUND);
//Setting the stage
Group root = new Group(
circle, ellipse, rect, poly, line,
polyLine, cubicCurve, quadCurve, arc,
cirText, rectText, ellipseText, polyText, lineText,
polyLineText, cubicCurveText, quadCurveText, arcText);
Scene scene = new Scene(root, 600, 300);
stage.setTitle("2D shapes Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} 출력
