为什么我收到此错误,该错误是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/