Skip to main content
gamedev.net
🔒 Locked

Java mouse problem

Started by spyral Apr 8, 2005 at 6:52 PM 1 replies 600+ views
Original Post
spyral
spyral
I have recently been asking java coders in the community for advice on my "Connect the dots" game, and thank you all. I have done what you have all said, and it has all worked thank you. I have the since then placing code where it needs to be. I only have one last question, and my entire game should be complete. How can I make the JPanel use the mouse events that I have already pre-programmed with the first game applet, so I don't have to take a good week re-programming. I have tried adding MouseListener to the JPanel, but that doesn't work. I have also tried putting the mehtod inside the JPanel but that doesn't work, is their anything that I am missing? Please do what you can, if you need to see source, please just ask. Thanks!!!!
Dave Hunt
Dave Hunt
For the JPanel to receive mouse events, it must be a MouseListener and have focus. You may need to force focus to the JPanel when the main window gets focus so that it can pick up the events. I've forgotten the method for requesting focus (probably something simple like requestFocus), but the JPanel docs should help you there.
stormrunner
stormrunner
Aye, Dave Hunt is correct. However, sifting through the JComponent docs showed that you should call requestFocusInWindow() instead of requestFocus(), because the latter is platform dependent.
stormrunner

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.