Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 找不到鼠标的坐标 我对代码非常陌生,目前我正在做我的第一个项目,(只是一个简单的游戏),这里是一些代码的快照。这辆车停了下来。向下、左键和右键工作正常,但行“mouse=newpoint(e.getX(),e.getY(),-25);”尽管安装了“公共点鼠标”,但似乎找不到鼠标的坐标。有什么建议吗 public Rectangle character; public int charW = 24; public int charH = 36; public boolean right = false; public boolean left = false; public boolean up = false; public boolean down = false; public boolean mouseActive = false; /** * */ public Point mouse; public Keying(Display f, Images i){ character = new Rectangle(180, 180, charW, charH); f.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_D){ mouseActive = false; right = true; character.x += 1; } if(e.getKeyCode() == KeyEvent.VK_A){ mouseActive = false; left = true; character.x -= 1; } if(e.getKeyCode() == KeyEvent.VK_W){ mouseActive = false; up = true; character.y -= 1; } if(e.getKeyCode() == KeyEvent.VK_S){ mouseActive = false; down = true; character.y += 1; } if(e.getKeyCode() == KeyEvent.VK_M){ mouseActive = true; } } public void keyReleased(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_D){ right = false; } if(e.getKeyCode() == KeyEvent.VK_A){ left = false; } if(e.getKeyCode() == KeyEvent.VK_W){ up = false; } if(e.getKeyCode() == KeyEvent.VK_S){ down = false; } } }); f.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e){ mouse = new Point(e.getX(), e.getY(), -25); if(mouseActive){ character.x = mouse.x; character.y = mouse.y; } repaint(); } }); } public void paintComponent(Graphics g){ super.paintComponent(g); this.setBackground(Color.BLACK); g.setColor(Color.RED); g.fillRect(character.x, character.y, character.width, character.height); if(right){ character.x += 1; } if(left){ character.x -= 1; } if(up){ character.y -= 1; } if(down){ character.y += 1; } repaint(); }_Java - Fatal编程技术网

Java 找不到鼠标的坐标 我对代码非常陌生,目前我正在做我的第一个项目,(只是一个简单的游戏),这里是一些代码的快照。这辆车停了下来。向下、左键和右键工作正常,但行“mouse=newpoint(e.getX(),e.getY(),-25);”尽管安装了“公共点鼠标”,但似乎找不到鼠标的坐标。有什么建议吗 public Rectangle character; public int charW = 24; public int charH = 36; public boolean right = false; public boolean left = false; public boolean up = false; public boolean down = false; public boolean mouseActive = false; /** * */ public Point mouse; public Keying(Display f, Images i){ character = new Rectangle(180, 180, charW, charH); f.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_D){ mouseActive = false; right = true; character.x += 1; } if(e.getKeyCode() == KeyEvent.VK_A){ mouseActive = false; left = true; character.x -= 1; } if(e.getKeyCode() == KeyEvent.VK_W){ mouseActive = false; up = true; character.y -= 1; } if(e.getKeyCode() == KeyEvent.VK_S){ mouseActive = false; down = true; character.y += 1; } if(e.getKeyCode() == KeyEvent.VK_M){ mouseActive = true; } } public void keyReleased(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_D){ right = false; } if(e.getKeyCode() == KeyEvent.VK_A){ left = false; } if(e.getKeyCode() == KeyEvent.VK_W){ up = false; } if(e.getKeyCode() == KeyEvent.VK_S){ down = false; } } }); f.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e){ mouse = new Point(e.getX(), e.getY(), -25); if(mouseActive){ character.x = mouse.x; character.y = mouse.y; } repaint(); } }); } public void paintComponent(Graphics g){ super.paintComponent(g); this.setBackground(Color.BLACK); g.setColor(Color.RED); g.fillRect(character.x, character.y, character.width, character.height); if(right){ character.x += 1; } if(left){ character.x -= 1; } if(up){ character.y -= 1; } if(down){ character.y += 1; } repaint(); }

Java 找不到鼠标的坐标 我对代码非常陌生,目前我正在做我的第一个项目,(只是一个简单的游戏),这里是一些代码的快照。这辆车停了下来。向下、左键和右键工作正常,但行“mouse=newpoint(e.getX(),e.getY(),-25);”尽管安装了“公共点鼠标”,但似乎找不到鼠标的坐标。有什么建议吗 public Rectangle character; public int charW = 24; public int charH = 36; public boolean right = false; public boolean left = false; public boolean up = false; public boolean down = false; public boolean mouseActive = false; /** * */ public Point mouse; public Keying(Display f, Images i){ character = new Rectangle(180, 180, charW, charH); f.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_D){ mouseActive = false; right = true; character.x += 1; } if(e.getKeyCode() == KeyEvent.VK_A){ mouseActive = false; left = true; character.x -= 1; } if(e.getKeyCode() == KeyEvent.VK_W){ mouseActive = false; up = true; character.y -= 1; } if(e.getKeyCode() == KeyEvent.VK_S){ mouseActive = false; down = true; character.y += 1; } if(e.getKeyCode() == KeyEvent.VK_M){ mouseActive = true; } } public void keyReleased(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_D){ right = false; } if(e.getKeyCode() == KeyEvent.VK_A){ left = false; } if(e.getKeyCode() == KeyEvent.VK_W){ up = false; } if(e.getKeyCode() == KeyEvent.VK_S){ down = false; } } }); f.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e){ mouse = new Point(e.getX(), e.getY(), -25); if(mouseActive){ character.x = mouse.x; character.y = mouse.y; } repaint(); } }); } public void paintComponent(Graphics g){ super.paintComponent(g); this.setBackground(Color.BLACK); g.setColor(Color.RED); g.fillRect(character.x, character.y, character.width, character.height); if(right){ character.x += 1; } if(left){ character.x -= 1; } if(up){ character.y -= 1; } if(down){ character.y += 1; } repaint(); },java,Java,MouseEvent对象有一个名为getPoint()的方法。这将允许您获得准确的点,而无需使用X和Y值创建一个新点 因此,请尝试更改行: mouse=新点(e.getX(),e.getY(),-25) 对下列事项: mouse=e.getPoint() 所有这些信息都可以在JavaDoc中找到,用于MouseEvent我自己设法做到了,但是如果有人想知道我做了什么,这是我使用的代码行- public void mouseMoved(MouseEvent e){

MouseEvent
对象有一个名为
getPoint()
的方法。这将允许您获得准确的
,而无需使用X和Y值创建一个新点

因此,请尝试更改行:

mouse=新点(e.getX(),e.getY(),-25)

对下列事项:

mouse=e.getPoint()


所有这些信息都可以在JavaDoc中找到,用于
MouseEvent

我自己设法做到了,但是如果有人想知道我做了什么,这是我使用的代码行-

    public void mouseMoved(MouseEvent e){
            int mouseX = e.getX();
            int mouseY = e.getY();
            mouse = new Point(mouseX, mouseY);

不管怎样,我只是自己做了,和你做的有点不同,但效果一样好,谢谢!别担心!祝你的项目好运:)谢谢!到目前为止一切进展顺利