Removing Listener: "variable mouseListener might not have been initialized"
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I choose the available option "initiatialize variable mouseListener"
After compiling, I receive the error message "cannot assign a value to final variable mouseListener"
Last evening while working on this I researched and came across a way to accomplish my goal. I am using what I see as a reference.
The following snippet demonstrates creating this reference to mouseListener:
At this time, after compile, I'm receiving an error message that using = null is not permitted (which appears to send me into a sort of circle, hence the apparent need for a reference.)
(The primary goal is to remove a mouselistener in order to simulate mouse freeze but first I need to figure this out. Thank you kindly for any nudge in the correct direction.)
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
In your case here the final keyword behaviour is in opposition to your intended design so you'll want to remove it.
Tim Driven Development | Test until the fear goes away
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Tim Cooke wrote:If you need to reassign different objects to a variable then it cannot be final. By declaring your variable as final you are telling the compiler that once it has been assigned an object then you have no intention of ever changing your mind and you want the compiler to forbid it.
In your case here the final keyword behaviour is in opposition to your intended design so you'll want to remove it.
When I remove Final, I receive the error "local variables referenced from an inner class must be final or effectively final"
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Declaring and assigning the final variable at the same time will resolve your problems related to variable assignment. E.g:
Tim Driven Development | Test until the fear goes away
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Tim Driven Development | Test until the fear goes away
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Tim Cooke wrote:On the implementation of the FreezableMouseListener, you got some solid advice in your other topic a few days ago that should put you in the right direction with it.
I greatly appreciate the assistance and while busy attempting to implement this, new issues have cropped up and while in the same area of the project, the answers seem entirely different. Thanks again.
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
@Mat
If you use (see lines 1 and 2 in your opening post)
then, for the compiler, mouseListener is a MouseListener. And so you cannot directly do:
because addMouseMotionListener requires a MouseMotionListener, and not a MouseListener.
A simple remedy would be what is called a CAST (transforming for a moment from one type to another type)
But much easier is it to declare:
and then in the constructor:
And since a MouseAdapter is both a MouseListener and a MouseMotionListener, you can simply do:
This is what I did in the code in the previous topic, that Tim referred to in his post.
There are three kinds of actuaries: those who can count, and those who can't.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
| It's a tiny ad only because the water is so cold. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









