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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:17:29+00:00 2026-06-03T17:17:29+00:00

I’m following this [slightly old tutorial for 2d java games here][1]. I have a

  • 0

I’m following this [slightly old tutorial for 2d java games here][1].

I have a basic applet that runs in a thread with a mouselistener.

On left button click I can shoot up to 10 claypigeons (balls) from the bottom of the window. On right button click I “shoot” and if I hit a pigeon it is removed from the screen.

I’ve noticed however that sometimes right clicks are not getting picked up. This is not necessarily when there is a lot going on on the screen, although never at the beginning before it all kicks off. At worst it can take 3 or 4 clicks before one is registered.

I’m guessing that I’m doing something obviously wrong in my code, but I’m not sure what. My first thought was the for loops that loop through every object every frame to recalculate their position or check if they have been “shot”? Could they been “blocking” the mouselistener?!

Any tips on how to debug this are welcome!

*********EDIT***********

Ok I’ve taken the very good advice given below and reduced the code to the smallest nutshell that reproduces the bug. I think I had it in my head that it was all the for loops and the complexity that were causing the problems which is why I included so much in my first code.

So as it happens I can reproduce this bug with almost no code, but at the same time it the bug is much milder. With the code below I just have the basic applet and the mouselistener and on right click a count increments in console and prints its value to screen. This works fine most of the time, but every now and again, a right click is “lost” and not registered.

With the full class, I could sometimes get sequences of 3 or 4 or more right clicks not being registered, so the bug was much more obvious. Anyway code is below, only one class this time:

Main class code:

package javacooperation;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;

public class ClayPigeonGame extends Applet implements Runnable, MouseListener {
    //counters and flags for debugging
    private boolean flag = true;
    private int click_count = 0;
    private boolean game_running;

    public void init(){
        //set boolean for while loop
        game_running=true;
        addMouseListener(this);
    }
    public void start() {
        //threading this applet.. why?
        Thread th = new Thread(this);
        //does this call the run method in the class?
        th.start();
    }

    public void stop(){
        game_running=false;
    }

    public void destroy() { }

    public void run(){
        while(game_running) {
            //updatePigeonPosition();
            repaint();
            try{
                //stop thread for 20 milliseconds
                Thread.sleep(20);
            } catch (InterruptedException ex){ }
        }
    }

    public void paint(Graphics g){  }

    public void mouseClicked(MouseEvent e) {
            switch (e.getButton()){
                case MouseEvent.BUTTON1:
                case MouseEvent.BUTTON2:
                    break;
                case MouseEvent.BUTTON3:
                    click_count ++;
                    System.out.println("Right click count: " + click_count);
                    break;
                default:
                    break;
            }
    }
    //all the mouse listening events required because we implemented MouseListener
    public void mouseReleased(MouseEvent e) { }
    public void mouseEntered(MouseEvent e) { }
    public void mousePressed(MouseEvent e) { }
    public void mouseExited(MouseEvent e) { }
}
  • 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-03T17:17:32+00:00Added an answer on June 3, 2026 at 5:17 pm

    It’s possible I guess that your code is interfering with the mouse clicked detection timing as a click is actually both a press and a release with the correct bounds etc. Have you tried not using the clicked call back and instead use the pressed (move the code to mousePressed instead) ?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.