Skip to main content
gamedev.net
🔒 Locked

Java Mouse & Keyboard listeners

Started by furiousp Feb 25, 2005 at 7:44 AM 0 replies 650+ views
Original Post
furiousp
furiousp
I'm writing a board game in java, i had all of my classes to handle mouse and keyboard events stored in seperate files. I'm trying to put all of these classes into 1 file to tidy up my code. I've put them all into a file called EventHandler. EventHandler is a public class and it contains all of the mouse and keyboard classes i need. The problem is when i try to declare an instance of one of these classes, like so: EventHandler.BoardMouse mouse = new EventHandler.BoardMouse(); I get the error: "an enclosing instance that contains EventHandler.BoardMouse is required" Does anyone know how to overcome this problem? Thanks [Edited by - furiousp on February 25, 2005 8:01:02 AM]
OrangyTang
OrangyTang
Quote:
Original post by furiousp
I'm writing a board game in java, i had all of my classes to handle mouse and keyboard events stored in seperate files. I'm trying to put all of these classes into 1 file to tidy up my code.

It's generally considered bad form to mung multiple classes together in one file in Java - if they consist of a single lump of functionality packages are generally prefered. If all your classes are tiny and have near no functionality then ignore the above.

Quote:

I get the error: "an enclosing instance that contains EventHandler.BoardMouse is required"

Does anyone know how to overcome this problem?

Thanks

Inner classes have an implicit pointer to their enclosing object (which is why trantional keyboard handling inner classes can poke around with member data of their constructing class). So if you create an inner class from somewhere else other than an instance of EventHandler then it doesn't know what this implicit pointer should refer to (which is a pretty strong suggestion that you actually want them in seperate files).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.