Mouse class not static

Started by cowdozer, February 01, 2006, 08:02:36

Previous topic - Next topic

cowdozer

Hi, I'm very new to the LWJGL, and I'm confused as to why the Mouse class is not declared static.  Absolutely everything inside the class is static.  It's the same with the Keyboard class too.  It seems very unusual to not have it static, and then make the constructor method private.

I would like to make my own mouse class (let's call it class MyMouse) that extends this Mouse class, but as it is, I'm confused as how to do this.  I don't believe that I can make the MyMouse class static because it's extending a non-static class, and Eclipse isn't liking the constructor I make.

The error I get is "Implicit super constructor Mouse() is not visible. Must explicitly invoke another constructor."  I am not sure how to get around this.

Also, as a side question, is the Mouse class able to tell you if a mouse button is being held down, double-clicked, or anything other than "Yes, the button is depressed", or "No, the button is not depressed"?  If not, would you just do the following if you wanted something to happen on click but not continuously if the mouse is held down:

private static final int LEFT = 0;
private static boolean lp;  //true if left mouse button is held down
if (Mouse.isButtonDown(LEFT) && !lp)
		{
			//do this only once per click
		}
if (!Mouse.isButtonDown(LEFT))
		{
			lp = false;
		}


Thanks!

Fool Running

QuoteHi, I'm very new to the LWJGL, and I'm confused as to why the Mouse class is not declared static. Absolutely everything inside the class is static. It's the same with the Keyboard class too. It seems very unusual to not have it static, and then make the constructor method private.
What exactly do you mean by "make the class static?" I'm pretty sure (someone can correct me on this :lol: ) that classes can't be declared static. The way to make them "static" is by doing what they are doing: making all of the methods and variables static and making a private constructor.
QuoteI would like to make my own mouse class (let's call it class MyMouse) that extends this Mouse class, but as it is, I'm confused as how to do this. I don't believe that I can make the MyMouse class static because it's extending a non-static class, and Eclipse isn't liking the constructor I make.
You can't extend most of the classes in LWJGL, you have to either call them or setup static imports.
QuoteThe error I get is "Implicit super constructor Mouse() is not visible. Must explicitly invoke another constructor." I am not sure how to get around this.
This is caused by the private constructor. As it is currently set up, there is no way that the Mouse class can be extended, sorry :( (unless you count static imports :? )
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Whackjack

QuoteI'm pretty sure (someone can correct me on this Laughing ) that classes can't be declared static.
Mostly correct... You can declare inner classes as static (think System.out).
Regardless, what you were referring to is correct.  You don't declare "normal" classes as static.  
Quotemaking all of the methods and variables static and making a private constructor.
That's all there is to making a "static" class.

Fool Running

QuoteMostly correct... You can declare inner classes as static (think System.out).
I didn't realize that. 8)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

cowdozer

Oh, weird.  I guess I forgot about that.  :oops:   So.... That seems sort of dumb that you can't extend those classes.  So what does everyone do then?  Are all of your main classes really huge, or how would you suggest breaking up the code into multiple files, so that you've got one that does the graphics stuff, one that does the keyboard input, one that does the mouse input, and then the main class mostly handles initialization, the game loop, and cleanup?

Also, was I correct about what you have to do for the Mouse class, to recognize if a button is being held down or just clicked?  Thanks a lot for the help!

aldacron

Quote from: "cowdozer"That seems sort of dumb that you can't extend those classes.

No, it's not dumb at all. You don't need to extend them. Since all of the methods are public and static you can call them anytime and anywhere.

Quote from: "cowdozer"So what does everyone do then?

The first step is to learn more about Java ;) You have demonstrated a misunderstanding of some basic concepts. In the meantime, perhaps this Asteroids tutorial from kevglass can help point you in the right direction.

tomb

Quote from: "cowdozer"
Also, was I correct about what you have to do for the Mouse class, to recognize if a button is being held down or just clicked?  Thanks a lot for the help!

You can get pressed and released "events" by using Mouse.next(). Look at its javadoc for detail. Clicks (press+release), double clicks and drags you have to implement yourself.

cowdozer

Quote from: "tomb"
You can get pressed and released "events" by using Mouse.next(). Look at its javadoc for detail. Clicks (press+release), double clicks and drags you have to implement yourself.

I have looked at the LWGJL javadoc regarding the Mouse class and it was confusing as to how one would use it most effectively, but this helps a lot.  Thank you.

Quote from: "aldacron"
Quote from: "cowdozer"
That seems sort of dumb that you can't extend those classes.
No, it's not dumb at all. You don't need to extend them. Since all of the methods are public and static you can call them anytime and anywhere.

I understand that you can call them anytime and anywhere, and I consider that a bit of a problem.  If I wanted a mouse class that was similar to Mouse, but provided support for more advanced mouse actions, such as if the mouse is being dragged, clicked, or double-clicked, I would have to outright copy the code from class Mouse into my new class, and make it that way.  I can't implement a wrapper class, because (ignoring the fact that I'd have to write a lot of methods that just call similar methods in the Mouse class) you would then be able to call the same method two different ways (because you can call the Mouse methods anytime and anywhere).

I know that I don't need to extend the Mouse class, but I would like to, and the fact that I can't is rather annoying when I feel I have reason to do so.

Quote from: "aldacron"
The first step is to learn more about Java  :wink:  You have demonstrated a misunderstanding of some basic concepts. In the meantime, perhaps this Asteroids tutorial from kevglass can help point you in the right direction.

I'm sorry, it's been a couple years since I took COSC 111/121 with Java, and I do realize that I've forgotten a fair bit.  School will do that to you.  I also tend to lean towards writing my own code so that I know exactly how it works, rather than using premade classes.  After learning about Generics, I realize how useful it can be to standardize your code with others' code, and I am getting used to looking for premade classes before making my own.  Because I tend to write my own code, I may simply have never before tried to extend a class with a private constructor.

...

:(  
Does anyone know of a forum I can go to where I can get help without feeling like I'm wasting their time?

Fool Running

LWJGL is a bare-bones wrapper for things like graphics and input.  Anything fancy you want to do (such as seeing if the mouse was dragged) has to be done yourself.
QuoteI understand that you can call them anytime and anywhere, and I consider that a bit of a problem. If I wanted a mouse class that was similar to Mouse, but provided support for more advanced mouse actions, such as if the mouse is being dragged, clicked, or double-clicked, I would have to outright copy the code from class Mouse into my new class, and make it that way. I can't implement a wrapper class, because (ignoring the fact that I'd have to write a lot of methods that just call similar methods in the Mouse class) you would then be able to call the same method two different ways (because you can call the Mouse methods anytime and anywhere).
I don't think its as bad as you think... Just create a wrapper that manages the calls to the Mouse class. Create a method that gets called every frame of your game. In that method create a loop that loops while there are mouse events. Read the event and set flags (or whatever) for the things you need (i.e. a double-click would be a press-release-press-release)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

cowdozer

Okay, thanks for the information, Fool Running.  I'll work on it.