Reputation: 55
Why am I getting this error, which is bruh.setLocation(bruh.x + 2, bruh.y); The errors are the x and y variables. How would I fix this issue?
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) {
}
}
Upvotes: 1
Views: 150
Reputation: 35011
The error is that bruh
is an Image and Image does not have a setLocation method
Upvotes: 1