用JavaFx画一条直线?

问题描述

下面的代码可以在窗格中的任何位置草绘(绘制)。我的问题是,如何更改此代码以使其绘制直线而不是直线。

您可以在图片中看到,我想使用我的代码将这些行转换为直线。

"lines"

能帮我吗,谢谢您的努力。

预期代码在以下---->

/
public class JavaApplication17 extends Application {
Pane canvas;
public static Stack <Object> Lines= new Stack <Object>();
    
double x1;
double x2;
double y1;
double y2;

    public void draw(){
    canvas.setOnMousePressed(e->{

          Lines.push(new Polyline()); 
             
             ((Polyline)Lines.peek()).setStroke(Color.RED); 
        ((Polyline)Lines.peek()).setStrokeWidth(3);
        
        y1 = e.getSceneY();
        x1 = e.getSceneX();
        
        
         ((Polyline)Lines.peek()).getPoints().addAll(x1,y1);
    
      
         canvas.getChildren().add(((Polyline)Lines.peek())); 
          
      });
      
   
      canvas.setOnMouseDragged(e->{
      
        y2 = e.getSceneY();
        x2 = e.getSceneX();
        
          ((Polyline)Lines.peek()).getPoints().addAll(x2,y2 );
      });
      
      
      
    
      
    }
    
    
    
  public void start(Stage primaryStage){
      
         
       canvas = new Pane();
       

      draw();
      
      Scene scene = new Scene(canvas,1080,720);
     
      primaryStage.setScene(scene);
      primaryStage.show();
      
  }
  
      public static void main(String[] args) {
       Application.launch();
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...