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

  • Home
  • SEARCH
  • 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 8326533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:47:34+00:00 2026-06-09T00:47:34+00:00

My problem is when I click in the space of the frame screen it

  • 0

My problem is when I click in the space of the frame screen it stops keyboard keys being registered so my player stop moving.

Thanks in advance for the help.

The code:

private Component comp;
....

public InputManager(Component comp) {
    this.comp = comp;
    mouseLocation = new Point();
    centerLocation = new Point();

    // register key and mouse listeners
    comp.addKeyListener(this);
    comp.addMouseListener(this);
    comp.addMouseMotionListener(this);
    comp.addMouseWheelListener(this);

    // allow input of the TAB key and other keys normally
    // used for focus traversal
    comp.setFocusTraversalKeysEnabled(false);
}

GUI code:

Game game = new Game();
    game.setMinimumSize(new Dimension(WIDTH * 2, HEIGHT * 2));
    game.setPreferredSize(new Dimension(WIDTH * 2, HEIGHT * 2));
    game.setMaximumSize(new Dimension(WIDTH * 2, HEIGHT * 2));

    frame = new JFrame(Game.NAME);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(game);
    frame.pack();
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    game.start();
  • 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-09T00:47:36+00:00Added an answer on June 9, 2026 at 12:47 am

    I assume that you are using a KeyListener to listen for key input. Note that this will only work when the component being listened to have focus, and likely when you press the mouse on the JFrame, your listened to component loses focus.

    The solution is not to use a KeyListener but instead use Key Bindings which are more robust than a KeyListener and a higher level concept.

    Also, you’ll want to stop using this as your listener. If your program grows to be anything more than a toy program, it gets very hard to maintain a GUI class that uses itself as its own listeners.

    Also, regarding: “oh yeah Game.java extends Canvas”: You don’t want to mix AWT and Swing components unnecessarily as this can cause side effects. Instead just use all Swing components such as JPanels instead of Canvases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a strange ToolStripButton double click problem. These steps will reproduce the problem:
Simple problem (I think): I want to be able to invoke a click method
My problem is that I can only seem to click the button once, if
I have a problem that when I click on the image button instead of
My problem is when dialog box is showing at that time may i click
Right now the problem is that the first time when I click the image,
I am facing a problem while disabling the command button after one click. I
I have problem while loading data into html select when users press or click
i have this annoying problem with my site where, when you click on a
I have a problem with an animation in jQuery using ajax. On the click

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.