Welcome to the Ex Lumina Corp. J360Controller tutorials. With J360Controller, your Java application for Windows can use an XBox 360 USB controller as part, or even all, of its user interface. You can play games, control other devices, provide accessibility tools, or do any number of other things that work well with this popular input device.

These tutorials are each short, stand-alone examples of how to accept input from the XBox 360 controller's buttons, triggers, and thumbsticks. They explain, with working examples, all of the features and options available to you from J360Controller. You don't need to use them all in a single program, and you don't even have to learn how to use them all. We'll cover a few basic concepts before moving on to code-based examples, so you can choose which tutorials are right for you. We'll cover each feature on its own, then wrap up with a simple example of how J360Controller makes it easy to write a game in Java.

Developer Options

Before you get started with your first tutorial, you'll want to know about the three options you have for using J360Controller. You don't need to use all of them, nor do you need to choose one and not make use of the others. Knowing a bit about all three will let you make the best choice for your application.


The first is the "polling" option. Under this option, you can simply read the positions of all the buttons, triggers, and thumbsticks on any one of four controllers any time you wish to do so. If you are writing a game with a main animation or simulation loop that repeatedly updates the display, you might want to use the polling option, as polling your controllers would naturally fit as a step in your animation or simulation loop.


The second option you have when using J360Controller is to use Java listeners. These are objects that implement a simple, one-method interface. Whenever a button is pressed or released, or when a trigger or thumbstick is moved on a controller, the new value of the button, trigger, or thumbstick is sent to the listener by calling its method, passing the value as an argument. For a button, the value is "true" if the button is pressed, and "false" if it is not pressed. For a trigger or a thumbstick, it is an integer somewhere in the range of possible values for that trigger or thumbstick. You can have a different listener for each button, each trigger, and each of the two directions that each thumbstick can move. Unlike polling, your listeners are only called when something changes, such a button being pressed or a thumbstick moving to a new position. If you are writing an application to control a device, or perhaps a media player, the listener option would be a good fit, as you will only want your code to respond to the specific events that a user initiates by pressing a button or moving lever.

Swing controls

The third option you have when using J360Controller is to assign one of several Swing controls to the button, triggers, or thumbsticks on your control, and have the controller operate those controls for you, somewhat like the way you use your mouse to operate them. For example, you can assign a JButton to the "X" button on a controller. When you press the "X" button, your application will behave the same way as it would if you had clicked on the JButton with your mouse. Using this option, you can quickly and easily add an XBox 360 controller to your existing application, choosing buttons and sliders that will continue to operate as they always have, but that you will now be able to control with your XBox 360 controller as well. This can be a good choice when you have a small set of operations that you might want to control while you are not sitting directly at your keyboard, such as a lighting control system or a camera stand.

Choosing an option

Again, the three options, polling, listeners, and Swing controls, are not mutually exclusive. Your application can use all three, mixing and matching for different buttons and levers as you choose. Before making a choice, we suggest that you read and try the first lesson in each of the three main tutorial sections. Those will show you how to write a simple Java program that reacts to the press of the "X" button on an XBox controller, using each of the three options available to you. After you've done that, you'll be in a good position to choose which option is best for your next application. There are also a few topics after the first three sections below that you'll want to cover as well, but those can wait until you've mastered the basics. Have fun and feel free to submit questions to our forum and problem reports or enhancement requests to our bug tracker.

« HomeLessons »