is LinuxJoystickPOV not subclassed from Component.POV? or am I doing this wrong?

I’m a rookie at this. I’m trying to pick up values from the hat of my joystick. So I have code like:

               Component comp = event.getComponent();
                if (comp instanceof Component.POV || comp instanceof LinuxJoystickPOV) {
                    System.out.println(" is hat");
                }

This works, but if the test is jut for the Component.POV, it fails.


            if (comp instanceof Component.POV ) {
                    System.out.println(" should still be a hat");
            }

What is the preferred way to check this?

Thanks
pat

Hi

What you need to be doing is getting the identifer for the component instead of checking the class. This should return Component.Identifier.Axis.POV. The other class is just statics for identifying the direction of the hat.

HTH

Endolf

Thanks for the reply. A code fragment:


                Component comp = event.getComponent();
                String compName = comp.getName();
                Component.Identifier compIdent = comp.getIdentifier();
                String compId = comp.getIdentifier().getName();
                buffer.append(String.format(" %s idt: %s  %s %s", comp, compName, compIdent, compId));

is returning “pov” for all values.

I’m not seeing anything returning the string “Component.Identifier.Axis.POV” or alternatively
“Component$Identifier$Axis$POV”

If I look at the class name of the “comp” it shows LinuxJoystickPOV

While I can just hard coded it to “pov” I would much rather use either a nice class name or a manifest constant from the package.

Thanks
Pat

What does the controller text test show?

pov(pov)

Don’t use the class names, use the component identifiers. That is what they are there for.

Endolf

I think you are missing some subtle things in my code. I get both the class and the identifier
and the debugging code shows all possible returned values.

So what constants in the package contain the value “pov”?

Looks like the constant I want is available with:

Axis.POV.getName()

or fully qualified:
net.java.games.input.Component.Identifier.Axis.POV.getName()