I was following a coding tutorial having to do with Key Events and all the code looks right, but for some reason there is an error that I can’t fix. Maybe all I need is another set of eyes to scan through it and spot my error. Here’s the code. There are 2 asterisks on either side of the line of code with the error. The error tells me that that a “;” (semicolon) is expected where the
“(” and “)” is…how does that even make sense ? I will also post a picture.
package com.Bench3.myGame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Keying extends JPanel{
public Rectangle character;
public int charW = 24;
public int charH = 36;
public boolean right = false;
public boolean left = false;
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){
right = true;
}
if(e.getKeyCode() == KeyEvent.VK_A){
left = true;
}
**public void keyReleased(KeyEvent e)**{
if(e.getKeyCode() == KeyEvent.VK_D){
right = false;
}
if(e.getKeyCode() == KeyEvent.VK_A){
left = false;
}
}
}
});
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.BLACK);
g.setColor(Color.WHITE);
g.fillRect(character.x, character.y, character.width, character.height);
if(right){
character.x += 1;
}
if(left){
character.x -= 1;
}
repaint();
}
}

You forgot to close the curly braces of previous method (
keyPressed()): –