java错误中的键事件

java错误中的键事件,java,image,swing,paintcomponent,keylistener,Java,Image,Swing,Paintcomponent,Keylistener,为什么会出现这个错误,即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();

为什么会出现这个错误,即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
也缺少
x
y
字段。