   [java] Mouse Input questions
  Hi all,I have a question about how the best way to implement mouse and keyboard input into my game is.  I usually code in C++ so I would make an input class that all other objects would query for the state of the keyboard and mouse.  I can't really do this in Java, so I was wondering, is the best way to handle input to implement MouseListener for every object that needs mouse input?  This is the way I was planning to do it, but I wanted to get feedback as to why this technique may not be all that great.  Thanks!   
Quote:Original post by Andybean9I can't really do this in JavaWhy not?[source lang=Java]public class Input implements MouseListener, MouseMotionListener, KeyListener {  private int mouseX, mouseY;  private boolean button[];  private boolean key[];  //and whatever else you want to track  private statice Input instance;  private Input() {  }  public static Input getInstance() {    if(instance == null) { instance = new Input();    }    return instance;  }  //implement all the getters  //implement this plus any other functionality you need.  public void mousePressed(MouseEvent e) {    mouseX = e.getX();    mouseY = e.getY();    button[e.getButton()] = true;  }  public void mouseReleased(MouseEvent e) {    mouseX = e.getX();    mouseY = e.getY();    button[e.getButton()] = false;  }  public void keyPressed(KeyEvent e) {    key[e.getKeyCode()] = true;  }  public void keyReleased(KeyEvent e) {    key[e.getKeyCode()] = false;  }}Most people would probably reccommend against doing this.  But you can use singletons to access the same instance of a class from anywhere.   ;  Apart from the singleton (which is a design-based choice), that's pretty much valid solution. You might want to monitor the swing event thread, though.Rodrigo   