public class SuperLabel extends JLabel implements MouseListener {
public SuperLabel() {
super();
this.addMouseListener([COLOR="#2e8b57"]this[/COLOR]);
}
public void mouseClicked(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
}
Here's my issue: I'm using the NetBeans IDE, and the hint system is flagging the "this" parameter (green in the above CODE block) in my constructor with the following message: "Passing suspicious parameter in the constructor."
I know exactly why it is doing this, because "this" may not be fully initialized yet. Naturally, this is to be expected, since we're still in the constructor.
My code works perfectly, however, my question is: Is this bad coding practice? Is there a reason why I should not do this? Is there a better way? (None of the code in the event handlers rely on any initialized variables, in case this matters. My question is strictly concerning Best Known Methods.)


Sign In
Create Account


Back to top









