我需要在我的应用程序中获取鼠标点击的x和y坐标.我通过创建一个点在下面的代码中部分地解决了它,但我不断得到不同的坐标,具体取决于我在屏幕上移动应用程序窗口的位置.我需要一些不变的东西来识别某些后来的东西.谢谢您的帮助!
@Override
public void start(Stage stage) throws Exception {
final Pane root = new Pane();
setWidth(1400);
setHeight(1000);
Canvas background = new Canvas(getWidth(), getHeight());
final GraphicsContext context = background.getGraphicsContext2D();
File f = new File("background.png");
final Image image = new Image(new FileInputStream(f));
root.getChildren().add(background);
root.getChildren().add(b1);
b1.setLayoutX(1300);
b1.setLayoutY(10);
final Canvas animation = new Canvas(getWidth(), getHeight());
final Canvas animation2 = new Canvas(getWidth(), getHeight());
animation.setMouseTransparent(true);
animation2.setMouseTransparent(true);
final GraphicsContext context2 = animation.getGraphicsContext2D();
final GraphicsContext context3 = animation2.getGraphicsContext2D();
root.getChildren().add(animation);
root.getChildren().add(animation2);
Scene scene = new Scene(root, getWidth(), getHeight());
stage.setTitle("Old …Run Code Online (Sandbox Code Playgroud) 我是C#的初学者.我有一个问题,你可以简单地解决.我有一个函数,用数字创建二维数组并返回它.我想在main()中使用这个函数来获取main()中的这个2D数组.这是一个不起作用的代码(它只打印"Y:").请你帮助我好吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Simulation
{
static int[,] Initialize(int x, int a, int b)
{
Random r = new Random();
int[,] positions = new int[2,x];
for(int i=0;i<x;i++){
positions[0,i]=a*r.Next();
positions[1,i]=b*r.Next();
}
return positions;
}
static void Main(string[] args)
{
int[,] array=Initialize(100,100,100);
System.Console.WriteLine("Y:", array[1, 1]);
System.Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
祝你有美好的一天!