• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Keeping the Mouse inside a JPanel

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My 3 year old son loves to use Paint Shop Pro. But he hasn't quite got the concept of the relationship between the mouse and the pointer on screen. So he spends half his time moving the mouse around outside of the painting area.

Anyway, I thought I could construct a very simple basic paint program if I could figure out someway to keep the mouse cursor inside a specified JPanel area. That way, he could move the mouse around as much as he wants and always be on the paintable canvas.

If anyone has any insight into this, please let me know.

Thanks.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just maximize the window in Paint Shop Pro? Or use some other drawing program that can make the drawing canvas full-screen? (The Gimp?)

brian
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I've got a similiar issue with my 3 year old daughter! I wanted to let her 'use' the computer like daddy, but she has a hard time clicking 'where she should'.

I've almost finished a program you might like. It opens a jframe that is maximized. The screen has 4 image areas, which have a randomly colored ellipse drawn. At the bottom is a rainbow colored next button.

As my daughter clicks the ellipse buttons, they switch to a picture. If she clicks them again, they switch back to a new colored ellipse. When the next button is clicked, the buttons all swap to new colored ellipses, with new pictures under them.

To add pictures, you simply drop whatever JPG/PNG/GIF you want into a picture directory and run the app. I've got pictures of her relatives and friends in the pics dir. I'm collecting pictures of her favorite child characters such as Dora, the Wiggles, Blue, etc, so she can uncover them as she's clicking around!

Everything is jumbo sized for her, so she can easily click and make things happen. I've just added sound to, so that a random sound is heard each time she clicks a button. Its not quite working right between 1.4.2 and 1.5.0beta.

I'd be happy to send it to you.

Regards,
Aaron R>
[ May 18, 2004: Message edited by: Aaron Roberts ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Roberts:
Hey I've got a similiar issue with my 3 year old daughter! I wanted to let her 'use' the computer like daddy, but she has a hard time clicking 'where she should'.

I've almost finished a program you might like. It opens a jframe that is maximized. The screen has 4 image areas, which have a randomly colored ellipse drawn. At the bottom is a rainbow colored next button.

As my daughter clicks the ellipse buttons, they switch to a picture. If she clicks them again, they switch back to a new colored ellipse. When the next button is clicked, the buttons all swap to new colored ellipses, with new pictures under them.

To add pictures, you simply drop whatever JPG/PNG/GIF you want into a picture directory and run the app. I've got pictures of her relatives and friends in the pics dir. I'm collecting pictures of her favorite child characters such as Dora, the Wiggles, Blue, etc, so she can uncover them as she's clicking around!

Everything is jumbo sized for her, so she can easily click and make things happen. I've just added sound to, so that a random sound is heard each time she clicks a button. Its not quite working right between 1.4.2 and 1.5.0beta.

I'd be happy to send it to you.

Regards,
Aaron R>

[ May 18, 2004: Message edited by: Aaron Roberts ]



Aaron, that would be great if you could send that to me.

I'd also like to figure out if what I want to do with the mouse and the canvas is possible. Thanks.
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could probably make a mouselistener that listened for exit events (when the mouse have left the component). Once this happens, you could use java.awt.Robot to reposition the mouse backinside the bounds of the drawing area.

Go to -

Game Source Code

and get the source code for ch3. Use ant to compile it. If you run the MouseTest or MouselookTest examples, you should get a good idea of how things could work. The examples are done in full screen mode, but they still apply.

I'll email you the code after I get home tonight.

Regards,
Aaron R>
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Roberts:
You could probably make a mouselistener that listened for exit events (when the mouse have left the component). Once this happens, you could use java.awt.Robot to reposition the mouse backinside the bounds of the drawing area.

Go to -

Game Source Code

and get the source code for ch3. Use ant to compile it. If you run the MouseTest or MouselookTest examples, you should get a good idea of how things could work. The examples are done in full screen mode, but they still apply.

I'll email you the code after I get home tonight.

Regards,
Aaron R>



Thanks Aaron!
 
reply
    Bookmark Topic Watch Topic
  • New Topic