Java Reference
In-Depth Information
radiusX
radiusY
length
startAngle
0 degree
(centerX, centerY)
(a) Arc(centerX, centerY, radiusX,
radiusY, startAngle, length)
(b) Multiple ellipses are displayed
F IGURE 14.36
An Arc object is created to display an arc.
L ISTING 14.18
ShowArc.java
1 import javafx.application.Application;
2 import javafx.scene.Scene;
3 import javafx.scene.layout.Pane;
4 import javafx.scene.paint.Color;
5 import javafx.stage.Stage;
6 import javafx.scene.shape.Arc;
7 import javafx.scene.shape.ArcType;
8 import javafx.scene.text.Text;
9
10 public class ShowArc extends Application {
11 @Override // Override the start method in the Application class
12
public void start(Stage primaryStage) {
13
// Create a pane
create a pane
14
Pane pane = new Pane();
15
16 Arc arc1 = new Arc( 150 , 100 , 80 , 80 , 30 , 35 ); // Create an arc
17 arc1.setFill(Color.RED); // Set fill color
18 arc1.setType(ArcType.ROUND); // Set arc type
19 pane.getChildren().add( new Text( 210 , 40 , "arc1: round" ));
20 pane.getChildren().add(arc1); // Add arc to pane
21
22 Arc arc2 = new Arc( 150 , 100 , 80 , 80 , 30 + 90 , 35 );
23 arc2.setFill(Color.WHITE);
24 arc2.setType(ArcType.OPEN);
25 arc2.setStroke(Color.BLACK);
26 pane.getChildren().add( new Text( 20 , 40 , "arc2: open" ));
27 pane.getChildren().add(arc2);
28
29 Arc arc3 = new Arc( 150 , 100 , 80 , 80 , 30 + 180 , 35 );
30 arc3.setFill(Color.WHITE);
31 arc3.setType(ArcType.CHORD);
32 arc3.setStroke(Color.BLACK);
33 pane.getChildren().add( new Text( 20 , 170 , "arc3: chord" ));
34 pane.getChildren().add(arc3);
35
36 Arc arc4 = new Arc( 150 , 100 , 80 , 80 , 30 + 270 , 35 );
37 arc4.setFill(Color.GREEN);
38 arc4.setType(ArcType.CHORD);
create arc1
set fill color for arc1
set arc1 as round arc
add arc1 to pane
create arc2
set fill color for arc2
set arc2 as round arc
add arc2 to pane
create arc3
set fill color for arc3
set arc3 as chord arc
add arc3 to pane
create arc4
 
 
Search WWH ::




Custom Search