Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8722111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:20:13+00:00 2026-06-13T07:20:13+00:00

I was following a coding tutorial having to do with Key Events and all

  • 0

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();
}

}
Here's the error up close. hope it helps THANK YOU !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:20:14+00:00Added an answer on June 13, 2026 at 7:20 am

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

    public void keyPressed(KeyEvent e){
            if(e.getKeyCode() == KeyEvent.VK_D){
                right = true;
            }
            if(e.getKeyCode() == KeyEvent.VK_A){
                left = true;
                }
    } // missing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie trying to learn some code. I am following the tutorial on
I am working on coding a GUI with C#. I'm following this simple tutorial
Consider the following code (for simplicity, I did not follow any C# coding rules).
Following this tutorial , I got to the end stages of coding the map
I have some problems using OpenSSL. I'm following the tutorial for compiling OpenSSL for
http://coding.pressbin.com/18/Display-a-Google-Map-when-you-hover-over-location-text/ I am following this tutorial on how to display google map over a
I use the following coding which edits my text file based on the value
i have following coding to resize image and than save it my virtual folder
i have a splash screen at start up. with the following coding public class
I have following UML class diagram and java coding for each, please tell me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.