I see all these samples that poll one component, has anyone made a listener

A listener that polls all components. Because I have never seen a game that uses only one button, they use multiple buttons all at the same time.

Sorry, I was looking at the api and I saw an Event class. I am not a hundred percent on how to make my own ActionListener. Can I just create an Action Listener with the Event from JInput. Would that work?

Nope. JInput is a polled API, you always have to poll it. If you want to do what you say, you could write a thread that polls the API and then calls in to your code on a listener interface, but it seems odd. Most games want control over the threading model, so polled APIs seem more acceptable to developers. It also reflects the underlying OS interface for input.

HTH

Endolf

ok what is the setup for polling all buttons? Do I need to make a component for every button and then each one?>

You have 2 options.

  1. The old way. Get the array of components from the controller, then poll the device and read each components data.
  2. The new way. Poll the device, get the event queue, and in each event it has the component the event relates too.

It’s all in the getting started information.

HTH

Endolf

Here’s how I do it, using a thread and creating a homemade event from the polled data.
(code is a snippet, it wont compile as is)
private final class ControllerEventThread extends Object implements Runnable {

	private Thread myThread = null;				
	private int mySleepTime;
	
	private long myLastEventTimeStamp;
	private boolean myIDLE;
	
	public ControllerEventThread() {
		this(EVENT_FETCH_WAIT_MS);
	}
	
	public ControllerEventThread(int sleepTimeInMillis) {
		super();			
		mySleepTime = sleepTimeInMillis;		
		myLastEventTimeStamp = 0;
	}
	
    public boolean isRunning() {
        return (null != myThread);
    }
    
	public boolean start() {
		if (null == myThread) {			    
		    myIDLE = false;
			myThread = new Thread(this);
			myController.setEventQueueSize(EVENT_FETCH_SIZE);
			myLastEventTimeStamp = System.nanoTime();
			myThread.start();
			if (log.isDebugEnabled()) {
				log.debug("ControllerEventThread started");
			}
			return true;
		}
		log.warn("ControllerEventThread already started.");
		return false;
	}
	
	public boolean stop() {
		if (null == myThread) {
			log.warn("ControllerEventThread not started.");
			return false;
		}
		myThread = null;
		myController.setEventQueueSize(0);
		myLastEventTimeStamp = 0;
		log.debug("ControllerEventThread stopped");
		return true;
	}
	
	public void run() {		   
		while (myThread != null) {			    
			if (myController.poll()) {
			    Event event = new Event();
				while (myController.getEventQueue().getNextEvent(event)) {
				    myIDLE = false;
				    myLastEventTimeStamp = System.nanoTime();
                    try {                            
                        GameController.this.fireGameControllerEvent(event);                                                      
                    }
                    catch (Exception e) {
                        log.error(e.getLocalizedMessage(), e);
                    }
				}//end while
			    long delay = System.nanoTime() - myLastEventTimeStamp;
			    if ((delay > EVENT_IDLE_NS) && (!myIDLE)) {                       
			        myIDLE = true;
                    GameController.this.fireGameControllerIDLE();                        
                }
				try {
                    if (mySleepTime > 0) {
                        myThread.sleep(mySleepTime);
                    }
                }
                catch (InterruptedException e) {                    
                    log.error(e.getLocalizedMessage(), e);
                    stop();
                }
			}
			else { 
				//not polled
				stop();					
				log.warn("Stopped because of loss of polled data. Controller must have been unplugged.");
			}				
		}//while
	}		
}

The drawback to this approach however is that
– There’s a lot of created event objects since each call to GameController.this.fireGameControllerEvent(event) creates a new one and some controllers don’t stop spamming events (the way you implement this method is up to you - in my case I create a new EventObject 90% of the time).
– The thread.wait() may introduce some lag in some cases and bursts of events. It may be a problem if you need something hyper-responsive but I’m happy with the results so far.

Hope this helps