....
package theShapes;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.shape.Line;
public class Test extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Shapes");
Group root = new Group();
//StackPane layout = new StackPane();
Scene scene= new Scene(root,600,400);
MyLine line1 = new MyLine(0.0,0.0,200.0,200.0);// doesn't work
//Line line1 = new Line(0.0,0.0,600.0,400.0);
root.getChildren().add(line1);//doesn't work
primaryStage.setScene(scene);
primaryStage.show();
}
}
package theShapes;
public class MyLine extends MyShape{
private double x2,y2;
MyLine(double x1, double y1,double x2, double y2) {
super(x1, y1);
setEndX(x2);
setEndY(y2);
}
public void setEndX(double x2){
this.x2 = x2;
}
public void setEndY(double y2){
this.y2 = y2;
}
}
package theShapes;
public class MyShape extends Object {
private double x1,y1;
//color
MyShape(double x1,double y1){//color
setStartX(x1);
setStartY(y1);
//color
}
public double getX1(){
return x1;
}
public double getY1(){
return y1;
}
public void setStartX(double x1){
this.x1 = x1;
}
public void setStartY(double y1){
this.y1 = y1;
}
}
...
Iполучил следующую ошибку:
Error:(25, 27) java: no suitable method found for add(theShapes.MyLine)
method java.util.Collection.add(javafx.scene.Node) is not applicable
(argument mismatch; theShapes.MyLine cannot be converted to
javafx.scene.Node)
method java.util.List.add(javafx.scene.Node) is not applicable
(argument mismatch; theShapes.MyLine cannot be converted to
javafx.scene.Node)
Я хочу переопределить класс Line с помощью myLine, но он не позволяет мне рисовать линию.