การดำเนินการนี้ใช้รูปร่างตั้งแต่สองรูปร่างขึ้นไปเป็นอินพุต จากนั้นจะส่งกลับพื้นที่ของรูปร่างแรกโดยไม่รวมพื้นที่ทับซ้อนกับรูปร่างที่สองดังที่แสดงด้านล่าง

การลบ() (คงที่) เมธอดของคลาส javafx.scene.shape.Shape ยอมรับออบเจ็กต์ Shape สองออบเจ็กต์และส่งคืนผลลัพธ์ของการดำเนินการลบของออบเจ็กต์ที่กำหนด
ตัวอย่าง
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Shape;
public class JavaFXSubtractExample extends Application {
public void start(Stage stage) {
//Drawing circle1
Circle circle1 = new Circle();
circle1.setCenterX(230.0f);
circle1.setCenterY(100.0f);
circle1.setRadius(75.0f);
circle1.setFill(Color.DARKRED);
//Drawing Circle2
Circle circle2 = new Circle();
circle2.setCenterX(280.0f);
circle2.setCenterY(170.0f);
circle2.setRadius(75.0f);
circle2.setFill(Color.DARKRED);
//Drawing Circle3
Circle circle3 = new Circle();
circle3.setCenterX(330.0f);
circle3.setCenterY(100.0f);
circle3.setRadius(75.0f);
circle3.setFill(Color.DARKRED);
//Intersect Operation
Shape subtract = Shape.subtract(circle1, circle2);
subtract = Shape.intersect(subtract, circle3);
subtract.setFill(Color.RED);
//Setting the stage
Group root = new Group(circle1, circle2, circle3, subtract);
Scene scene = new Scene(root, 595, 300);
stage.setTitle("Subtract Operation");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} ผลลัพธ์
