为什么我会收到此错误,即 bruh.setLocation(bruh.x + 2, bruh.y);误差是 x 和 y 变量。我该如何解决这个问题?
public void paintComponent(Graphics g){
super.paintComponent(g);
ImageIcon ii = new ImageIcon(this.getClass().getResource("bruh.png"));
bruh = ii.getImage();
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(bruh, x, y, this);
}
public void keyTyped(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT)
{
bruh.setLocation(bruh.x + 2, bruh.y);
}
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT)
{
}
}
public void keyReleased(KeyEvent e) {
}
}
最佳答案
错误是 bruh
是 Image并且 Image 没有 setLocation 方法
关于java - java 错误中的关键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27640167/