JStick, the simple joystick for Java Swing.
JStick is compatible with Java language level 8 or newer.
Add JStick to your Maven project by adding the following dependency to pom.xml
:
<dependency>
<groupId>net.scarlettsystems.java</groupId>
<artifactId>jstick</artifactId>
<version>0.0.2</version>
</dependency>
The component may be instantiated by simply calling its constructor:
JStick myJoystick = new JStick();
Adding the component to a panel will automatically have the joystick sized to fill its bounds:
JPanel panel = new JPanel();
panel.add(myJoystick);
Attach a listener to be fired each time motion is detected on the joystick:
myJoystick.addJoystickListener(new JStick.JoystickListener()
{
@Override
public void onJoystickMoved(JStick j)
{
int x = j.getStickX();
int y = j.getStickY();
//Do something useful
}
@Override
public void onJoystickClicked(JStick j)
{
}
});
There are several other configurable parameters including the colour and dead-zone. See the docs for more information.
The most current stable version is 0.0.2
- Shane Scarlett - core development - Scarlett Systems
This component was inspired by Sam Arthur Gilliam's Stackoverflow answer here, and contains heavily modified code from said post.
This project is licensed under the Apache 2.0 License.