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 8877755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:32:37+00:00 2026-06-14T19:32:37+00:00

I am making a two player game applet. Both players need to control their

  • 0

I am making a two player game applet. Both players need to control their discs to keep the ball from colliding with the wall. One player controls his disc with mouse motion and other controls with Keyboard up and down. The problem is the second player can’t control his disc because keyboard keys doesn’t remain in focus because of MouseMotionListener. I don’t know how to solve this problem. Here is the code:

public void init()
{
handle = new HandlerClass();

addMouseMotionListener(handle);
addKeyListener(handle);
}

private class HandlerClass implements MouseMotionListener,KeyListener
{       
public void mouseMoved(MouseEvent event)
{
    MouseY=event.getY();

    if(MouseY<=0)
        MouseY=0;
    else
        if(MouseY>=getHeight()-radius*2-1)
            MouseY=getHeight()-radius*2-1;

}
public void keyPressed(KeyEvent event)
{
    switch(event.getKeyCode())
    {
    case KeyEvent.VK_UP:

        if(keyboardY<=0)
        {
            keyboardY=0;
        }

        keyboardY=keyboardY+1;
        break;

    case KeyEvent.VK_DOWN:

        System.out.println("down key pressed");
        if(keyboardY>=getHeight()-radius*2-1)
        {
            keyboardY=getHeight()-radius*2-1;
        }
        keyboardY-=1;
        break;
    }
 }

EDIT:
I solve the problem of losing focus for keyboard by adding setFocusable(true); but now the game flickers as hell. I can’t what is going on in the game.
Regards

  • 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-14T19:32:38+00:00Added an answer on June 14, 2026 at 7:32 pm

    Use Key Bindings over KeyListener, it provides the ability to specify different focus contexts.

    In regard to you second question, it sounds like you’re painting directly onto a top level container. I’d post a separate question with example code.

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

Sidebar

Related Questions

I'm working on making a two player tic-tac-toe game, and am in the phase
I am making a php based application. When two users are logged in from
I am making a football game for Android. I have a class Player. Player
I ran into an issue while I'm making a 4 player chess game. I
So I'm making a game, and all objects derive from one GameObject class, which
I am making a 2 player drawing game ( Touch Game ). On the
How can one solve the word game Ghost? Ghost is a two player word
I'm making a simple rock, paper scissor game in Java, and I have two
I am making two sites at the moment and have come up to a
So Im making a two UIscrollview in my view. I'm using Ray Wenderlich 's

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.