com.centralnexus.input
Class Joystick

java.lang.Object
  |
  +--com.centralnexus.input.Joystick

public class Joystick
extends java.lang.Object

Device driver to a Windows joystick. This handles at least an x,y motion joystick. A joystick can be plugged in as any id, and the first joystick id may or may not be plugged in. In order to create a Joystick, you must use one of createInstance functions.

There are two ways to update the axis and button values. You can either:

  1. Add a JoystickListener to the joystick with addJoystickListener().
  2. Use the poll() function from you own thread.

Since:
June 10, 2000
See Also:
JoystickListener

Field Summary
static int BUTTON1
          These are the standard buttons.
static int BUTTON10
           
static int BUTTON11
           
static int BUTTON12
           
static int BUTTON13
           
static int BUTTON14
           
static int BUTTON15
           
static int BUTTON16
           
static int BUTTON17
           
static int BUTTON18
           
static int BUTTON19
           
static int BUTTON2
           
static int BUTTON20
           
static int BUTTON21
           
static int BUTTON22
           
static int BUTTON23
           
static int BUTTON24
           
static int BUTTON25
           
static int BUTTON26
           
static int BUTTON27
           
static int BUTTON28
           
static int BUTTON29
           
static int BUTTON3
           
static int BUTTON30
           
static int BUTTON31
           
static int BUTTON32
           
static int BUTTON4
           
static int BUTTON5
          These are the extended buttons
static int BUTTON6
           
static int BUTTON7
           
static int BUTTON8
           
static int BUTTON9
           
static int HAS_POV
          Does this joystick have a point-of-view control capability?
static int HAS_POV4DIR
          Does this joystick point-of-view support discrete values capability (centered, forward, backward, left, and right)?
static int HAS_POVCONT
          Does this joystick point-of-view support continuous degree bearings capability?
static int HAS_R
          Does this joystick have a r-axis capability?
static int HAS_U
          Does this joystick have a u-axis capability?
static int HAS_V
          Does this joystick have a v-axis capability?
static int HAS_Z
          Does this joystick have a z-axis capability?
static float POV_BACKWARD
          Point-of-view hat is pressed backward.
static float POV_CENTERED
          Point-of-view hat is in the neutral position.
static float POV_FORWARD
          Point-of-view hat is pressed forward.
static float POV_LEFT
          Point-of-view hat is being pressed to the left.
static float POV_RIGHT
          Point-of-view hat is pressed to the right.
 
Method Summary
 void addJoystickListener(JoystickListener l)
          Adds the specified joystick listener to receive joystick events from this joystick.
static Joystick createInstance()
          Start using the first available joystick.
static Joystick createInstance(int id)
          Start using a joystick with a specific id.
 int getButtons()
          Current state of joystick buttons.
 int getCapabilities()
          Get the Capability bits.
 boolean getCapability(int capability)
          Is a certain capability bit turned on?
 float getDeadZone()
          Size of the dead zone.
 int getID()
          The joystick id for the joystick connected to the computer.
 int getNumAxes()
          Number of axes currently in use by the joystick.
 int getNumButtons()
          Number of buttons on the joystick.
static int getNumDevices()
          Returns the number of joysticks supported by the joystick driver or zero when no driver is present.
 int getPollInterval()
          Get the time in milliseconds that the JoystickListeners get notified of this joystick events.
 float getPOV()
          Current position of the point-of-view control.
 float getR()
          The r value of a joystick has a range from -1 to 1.
 float getU()
          The u value of a joystick has a range from -1 to 1.
 float getV()
          The v value of a joystick has a range from -1 to 1.
 float getX()
          The x value of a joystick has a range from -1 to 1.
 float getY()
          The y value of a joystick has a range from -1 to 1.
 float getZ()
          The z value of a joystick has a range from -1 to 1.
 boolean isButtonDown(int button)
          Current state of a specific joystick button.
static boolean isPluggedIn(int id)
          Returns true when the joystick is plugged into the computer, false otherwise.
 void poll()
          This polls (updates) the joystick for its values.
 void removeJoystickListener(JoystickListener l)
          Removes the specified joystick listener so that it no longer receives joystick events from this joystick.
 void setDeadZone(double deadZoneVal)
          Synonym for setDeadZone(float)
 void setDeadZone(float deadZoneVal)
          Size of the dead zone.
 void setPollInterval(int pollMillis)
          Set the time in milliseconds that the JoystickListeners get notified of this joystick events.
 java.lang.String toString()
          Text description of this joystick without the axis values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HAS_Z

public static final int HAS_Z
Does this joystick have a z-axis capability?

See Also:
Constant Field Values

HAS_R

public static final int HAS_R
Does this joystick have a r-axis capability?

See Also:
Constant Field Values

HAS_U

public static final int HAS_U
Does this joystick have a u-axis capability?

See Also:
Constant Field Values

HAS_V

public static final int HAS_V
Does this joystick have a v-axis capability?

See Also:
Constant Field Values

HAS_POV

public static final int HAS_POV
Does this joystick have a point-of-view control capability?

See Also:
Constant Field Values

HAS_POV4DIR

public static final int HAS_POV4DIR
Does this joystick point-of-view support discrete values capability (centered, forward, backward, left, and right)?

See Also:
Constant Field Values

HAS_POVCONT

public static final int HAS_POVCONT
Does this joystick point-of-view support continuous degree bearings capability?

See Also:
Constant Field Values

POV_CENTERED

public static final float POV_CENTERED
Point-of-view hat is in the neutral position. The value -1 means the point-of-view hat has no angle to report.

See Also:
Constant Field Values

POV_FORWARD

public static final float POV_FORWARD
Point-of-view hat is pressed forward. The value 0 represents an orientation of 0.00 degrees (straight ahead).

See Also:
Constant Field Values

POV_RIGHT

public static final float POV_RIGHT
Point-of-view hat is pressed to the right. The value 9,000 represents an orientation of 90.00 degrees (to the right).

See Also:
Constant Field Values

POV_BACKWARD

public static final float POV_BACKWARD
Point-of-view hat is pressed backward. The value 18,000 represents an orientation of 180.00 degrees (to the rear).

See Also:
Constant Field Values

POV_LEFT

public static final float POV_LEFT
Point-of-view hat is being pressed to the left. The value 27,000 represents an orientation of 270.00 degrees (90.00 degrees to the left).

See Also:
Constant Field Values

BUTTON1

public static final int BUTTON1
These are the standard buttons.

See Also:
Constant Field Values

BUTTON2

public static final int BUTTON2
See Also:
Constant Field Values

BUTTON3

public static final int BUTTON3
See Also:
Constant Field Values

BUTTON4

public static final int BUTTON4
See Also:
Constant Field Values

BUTTON5

public static final int BUTTON5
These are the extended buttons

See Also:
Constant Field Values

BUTTON6

public static final int BUTTON6
See Also:
Constant Field Values

BUTTON7

public static final int BUTTON7
See Also:
Constant Field Values

BUTTON8

public static final int BUTTON8
See Also:
Constant Field Values

BUTTON9

public static final int BUTTON9
See Also:
Constant Field Values

BUTTON10

public static final int BUTTON10
See Also:
Constant Field Values

BUTTON11

public static final int BUTTON11
See Also:
Constant Field Values

BUTTON12

public static final int BUTTON12
See Also:
Constant Field Values

BUTTON13

public static final int BUTTON13
See Also:
Constant Field Values

BUTTON14

public static final int BUTTON14
See Also:
Constant Field Values

BUTTON15

public static final int BUTTON15
See Also:
Constant Field Values

BUTTON16

public static final int BUTTON16
See Also:
Constant Field Values

BUTTON17

public static final int BUTTON17
See Also:
Constant Field Values

BUTTON18

public static final int BUTTON18
See Also:
Constant Field Values

BUTTON19

public static final int BUTTON19
See Also:
Constant Field Values

BUTTON20

public static final int BUTTON20
See Also:
Constant Field Values

BUTTON21

public static final int BUTTON21
See Also:
Constant Field Values

BUTTON22

public static final int BUTTON22
See Also:
Constant Field Values

BUTTON23

public static final int BUTTON23
See Also:
Constant Field Values

BUTTON24

public static final int BUTTON24
See Also:
Constant Field Values

BUTTON25

public static final int BUTTON25
See Also:
Constant Field Values

BUTTON26

public static final int BUTTON26
See Also:
Constant Field Values

BUTTON27

public static final int BUTTON27
See Also:
Constant Field Values

BUTTON28

public static final int BUTTON28
See Also:
Constant Field Values

BUTTON29

public static final int BUTTON29
See Also:
Constant Field Values

BUTTON30

public static final int BUTTON30
See Also:
Constant Field Values

BUTTON31

public static final int BUTTON31
See Also:
Constant Field Values

BUTTON32

public static final int BUTTON32
See Also:
Constant Field Values
Method Detail

getNumDevices

public static final int getNumDevices()
Returns the number of joysticks supported by the joystick driver or zero when no driver is present.


isPluggedIn

public static boolean isPluggedIn(int id)
Returns true when the joystick is plugged into the computer, false otherwise. This function may do some initialization to get the joystick working.

Parameters:
id - The ID of the joystick where 0 <= id < getNumDevs().

createInstance

public static Joystick createInstance()
                               throws java.io.IOException
Start using the first available joystick.

Throws:
java.io.IOException - Thrown when a joystick is not plugged into the computer.

createInstance

public static Joystick createInstance(int id)
                               throws java.io.IOException
Start using a joystick with a specific id. This should be used when you know a specific joystick is plugged into the computer.

Parameters:
id - The joystick id to get joystick information from.
Throws:
java.io.IOException - Thrown when the joystick for the id is not plugged into the computer.

getID

public final int getID()
The joystick id for the joystick connected to the computer. The ID numbers have a range of 0 <= id < getNumDevices()

See Also:
getNumDevices()

poll

public void poll()
This polls (updates) the joystick for its values. This must be called after the owner is done with the old values.


getCapabilities

public int getCapabilities()
Get the Capability bits. These bits can be ORed together.

See Also:
getCapability(int)

getCapability

public final boolean getCapability(int capability)
Is a certain capability bit turned on?

See Also:
HAS_Z, HAS_R, HAS_U, HAS_V, HAS_POV, HAS_POV4DIR, HAS_POVCONT

getX

public float getX()
The x value of a joystick has a range from -1 to 1.


getY

public float getY()
The y value of a joystick has a range from -1 to 1.


getZ

public float getZ()
The z value of a joystick has a range from -1 to 1.

See Also:
getCapabilities()

getR

public float getR()
The r value of a joystick has a range from -1 to 1.

Returns:
the rudder value (4th axis of movement)
See Also:
getCapabilities()

getU

public float getU()
The u value of a joystick has a range from -1 to 1.

Returns:
the u value (5th axis of movement)
See Also:
getCapabilities()

getV

public float getV()
The v value of a joystick has a range from -1 to 1.

Returns:
the v value (6th axis of movement)
See Also:
getCapabilities()

getPOV

public float getPOV()
Current position of the point-of-view control. Values for this member are in the range 0 through 359.00. These values represent the angle, in degrees.

Returns:
the point of view
See Also:
getCapabilities()

getButtons

public int getButtons()
Current state of joystick buttons. To see which buttons are pressed, "&" the result with one of the BUTTON constants.

Returns:
the bits representing each button.
See Also:
BUTTON1, BUTTON2, BUTTON3, BUTTON4

isButtonDown

public boolean isButtonDown(int button)
Current state of a specific joystick button.

Parameters:
button - can be BUTTON1, BUTTON2, BUTTON3 and so on.
Returns:
true if the button is being pressed, false otherwise.
See Also:
BUTTON1, BUTTON2, BUTTON3, BUTTON4

getNumButtons

public int getNumButtons()
Number of buttons on the joystick.


getNumAxes

public int getNumAxes()
Number of axes currently in use by the joystick.


getDeadZone

public final float getDeadZone()
Size of the dead zone. The default value is 0.0.


setDeadZone

public final void setDeadZone(float deadZoneVal)
Size of the dead zone. The dead zone is the range of values of each axis that returns 0. For example, when the deadZone = 0.1 and joystick(x, y, z) = (-0.09, 0.5, 0.1), then joystick(x, y, z) = (0.0, 0.5, 0.0).

Throws:
java.lang.IllegalArgumentException - when deadZone is out of the range 0 <= deadZone <= 1.0.

setDeadZone

public final void setDeadZone(double deadZoneVal)
Synonym for setDeadZone(float)


addJoystickListener

public void addJoystickListener(JoystickListener l)
Adds the specified joystick listener to receive joystick events from this joystick. If l is null, no exception is thrown and no action is performed.

Parameters:
l - The joystick listener

removeJoystickListener

public void removeJoystickListener(JoystickListener l)
Removes the specified joystick listener so that it no longer receives joystick events from this joystick. If l is null, no exception is thrown and no action is performed.

Parameters:
l - The joystick listener

setPollInterval

public void setPollInterval(int pollMillis)
Set the time in milliseconds that the JoystickListeners get notified of this joystick events.


getPollInterval

public int getPollInterval()
Get the time in milliseconds that the JoystickListeners get notified of this joystick events.


toString

public java.lang.String toString()
Text description of this joystick without the axis values

Overrides:
toString in class java.lang.Object


Copyright © 2000-2003 George Rhoten
Java is a registered trademark of Sun Microsystems, Inc.