teleias

how to do action input map java

Mar 16th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. //how to do action input map java
  2.  
  3. InputMap imap = gameView.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  4. ActionMap amap = gameView.getActionMap();
  5. {
  6.     KeyStroke ks;  
  7.     EventEnum e;
  8.     String en;
  9.     Command c;
  10.        
  11.     ks = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
  12.     e = EventEnum.gameClockTick;
  13.     en = e.getOutputName();
  14.     imap.put(ks, en);
  15.     c = (Command)EventEnum.getActionFromEvent(e);
  16.     amap.put(en, c);
  17. }
  18.  
  19. InputMap imap = gameView.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  20. ActionMap amap = gameView.getActionMap();
  21. {
  22.     KeyStroke ks; //keystroke
  23.     String n;     //name
  24.     Command c;    //command
  25.        
  26.     ks = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
  27.     n = "GameClockTick";
  28.     imap.put(ks, n); //Places the keystroke as the key, and the name as the value.
  29.     c = getCommandFromName(n); //returns the singleton command that is named variable n.
  30.     amap.put(n, c);  //Places the name as the key, and the command as the value.
  31. }
Advertisement
Add Comment
Please, Sign In to add comment