Test if the button were pushed in joystick

i want When I press a specific button in joystick
an action will be occurs
Such as writing the name of the button in TextField

i use this code but did not work ?

 private void check(){
    JInputJoystick joystick = new JInputJoystick(Controller.Type.STICK);
    
     int selectedControllerIndex = getSelectedControllerName();
            Controller controller = foundControllers.get(selectedControllerIndex);
    while (joystick.isControllerConnected()) {
        // Go trough all components of the controller.
        Component[] components = controller.getComponents();
        
        System.out.print(Arrays.toString(components));
        
        for (Component component : components) {
            Identifier componentIdentifier = component.getIdentifier();

            // Buttons
            if(componentIdentifier.getName().matches("^[0-9]*$")){ // If the component identifier name contains only numbers, then this is a button.
                // Is button pressed?
                if(component.getPollData() == 0.0f) {
                    System.out.print("Button got pressed!");
                }
            }
        }
      
    }
}