• Post Reply Bookmark Topic Watch Topic
  • New Topic

Make mouse cursor visible on mouse movement

 
I Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Paweł Baczyński
Saloon Keeper
Posts: 1955
38
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried setCursor(Cursor.DEFAULT_CURSOR)?
 
I Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
Saloon Keeper
Posts: 1955
38
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!