I’m in a robotics class here at Lawrence Tech. University. The class is based around laptop robots running java. I thaught it would be great if I could drive my robot like a remote control car via my playstation controller (with usb adapter). The goal is to eventually control the robot across campus (LTU is a wireless campus) from my desk.
While trying to understand Jinput, I found the tutorial at https://freefodder.dev.java.net/tutorial/jinputTutorialOne.html
It’s a great tutorial, but the examples seem to be broken. Running in Eclipse 3.1.1 and on the command line with ant result in the same error for the ControllerDetails example.
"
Exception in thread “main” java.lang.NoSuchMethodError: net.java.games.input.Controller.getAxes()[Lnet/java/games/input/Axis;
at net.java.games.input.tutorialone.ControllerDetails.printControllerDetails(ControllerDetails.java:74)
at net.java.games.input.tutorialone.ControllerDetails.main(ControllerDetails.java:46)
"
I understand that the tutorial is out of date and may have been broken with new versions of Jinput. What I need is a solution for the example.
-Swift-
Here is the code for the example:
package net.java.games.input.tutorialone;
import net.java.games.input.Axis;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
/** A simple application that shows detailed information
* about one of the controllers.
*
* @author Robert Schuster
*/
public class ControllerDetails {
/** Shows details about the controller represented
* by an index number. Use ListControllers to find
* out which index belongs to which controller.
*
* @param args
*/
public static void main(String[] args) {
if (args.length < 1) {
printUsage();
} else {
// treat first argument as a number
try {
//int index = Integer.parseInt(args[0]);
int index = 2;
/* access the default controller environment
* which contains all identified controllers
*/
ControllerEnvironment ce =
ControllerEnvironment.getDefaultEnvironment();
// retrieve the available controllers
Controller[] controllers = ce.getControllers();
// fail if the number argument is not a valid index for the Controller array
if (index < 0 || index >= controllers.length) {
System.out.println(
"The provided index is out of range.\nUse a value between 0 and "
+ (controllers.length - 1));
return;
}
// hand control over to a method printing the details for this controller
printControllerDetails(controllers[index]);
} catch (NumberFormatException nfe) {
printUsage();
}
}
}
private static void printUsage() {
// show a hint if the parameter format was not correct
System.out.println("Start application with an index as an argument");
System.out.println(
"denoting the controller you want detailed information");
System.out.println("from.");
}
/** Prints an input controller's details to the console. The
* method is called recursively for each subcontroller.
*
* @param c
*/
private static void printControllerDetails(Controller c) {
// shows basic information about this controller
System.out.println("name: " + c.getName());
System.out.println("type: " + c.getType());
System.out.println("port: " + c.getPortType());
// shows information about each Axis instance of this controller
printAxesDetails(c.getAxes());
// shows details about this controller's subcontroller
Controller[] subControllers = c.getControllers();
if (subControllers.length > 0) {
for (int i = 0; i < subControllers.length; i++) {
System.out.println("subcontroller: " + i);
printControllerDetails(subControllers[i]);
}
}
}
/** Prints detailed information about each Axis instance in the given
* array.
*
* @param axes
*/
private static void printAxesDetails(Axis[] axes) {
if (axes.length > 0) {
System.out.println("axes:");
// iterate through all axes and print their information
for (int i = 0; i < axes.length; i++) {
System.out.println(
i
+ " - "
+ axes[i].getName()
+ " - "
+ axes[i].getIdentifier()
+ " - "
+ (axes[i].isRelative() ? "relative" : "absolute")
+ " - "
+ (axes[i].isNormalized() ? "normalized" : "arbitrary")
+ " - "
+ (axes[i].isAnalog() ? "analog" : "digital")
+ " - "
+ axes[i].getDeadZone());
}
}
}
}