• 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

Make mouse cursor visible on mouse movement

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

First of all, apologies if this is the wrong section.

I've been creating a digital clock using Java, and have made the mouse cursor invisible after a set period of time (40-seconds) and had the thought to make it visible again if mouse was moved.

Here's the code that makes it invisible:


And here is what I have so far for making it visible again:


I have tried using "setCursor(DEFAULT_CURSOR)" but NetBeans says that it "cannot find symbol"

Any help is appreciated
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried setCursor(Cursor.DEFAULT_CURSOR)?
 
I Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, its no longer throwing the error.

But now I'm not sure where to add the MouseMotionListener to.

When the program is run, the clock is instantiated and placed into a JFrame with the main method:


But placing "add(mouse)" or "addMouseMotionListener(mouse)" in that section doesn't work as it can't find "mouse", although the MouseMotionListener is declared before the main method.
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to guess as you are only showing parts of the code.
Is your mouse declared in the same class as your main method at top level (member of a class)?

If that's the case you need to make mouse a static variable if you want to access it inside main.

Generally, you should not create your frame inside main method.
See this link.


Also, about:

I Johnson wrote:But placing "add(mouse)" or "addMouseMotionListener(mouse)" in that section doesn't work...


What do you mean by doesn't work? Does it compile? Does it throw an exception? Post the error message. Also, read this page.

I Johnson wrote:...as it can't find "mouse", although the MouseMotionListener is declared before the main method.


It doesn't matter. If this is a class member, it could be declared after the main method. The problem is, static methods (and main is static) can only see static variables and your mouse variable is probably non-static.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic