Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/05/2008, 17:29
abulon
 
Fecha de Ingreso: diciembre-2006
Mensajes: 127
Antigüedad: 17 años, 11 meses
Puntos: 1
Sonrisa Respuesta: No responde el Array JButton con los KeyStrokes

La unica forma que lo hice hacer funcionar es de esta manera no haciendolo dentro del ciclo for

Código PHP:

KeyStroke cero 
KeyStroke.getKeyStroke('0');

map=arr[0].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(cero,"action");

ActionMap actionmap=arr[0].getActionMap();
actionmap.put("action",actionListener);




KeyStroke one KeyStroke.getKeyStroke('1');

map=arr[1].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(one,"action");

ActionMap actuno=arr[1].getActionMap();
actuno.put("action",actionListener);




KeyStroke twoKeyStroke.getKeyStroke('2');

map=arr[2].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(two,"action");

ActionMap acttwo=arr[2].getActionMap();
acttwo.put("action",actionListener);



KeyStroke threeKeyStroke.getKeyStroke('3');

map=arr[3].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(three,"action");

ActionMap actthree=arr[3].getActionMap();
actthree.put("action",actionListener);




KeyStroke fourKeyStroke.getKeyStroke('4');

map=arr[4].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(four,"action");

ActionMap actfour=arr[4].getActionMap();
actfour.put("action",actionListener);




KeyStroke fiveKeyStroke.getKeyStroke('5');

map=arr[5].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(five,"action");

ActionMap actfive=arr[5].getActionMap();
actfive.put("action",actionListener);




KeyStroke sixKeyStroke.getKeyStroke('6'); //KeyEvent.VK_NUMPAD6,0

map=arr[6].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(six,"action");

ActionMap actsix=arr[6].getActionMap();
actsix.put("action",actionListener);



KeyStroke sevenKeyStroke.getKeyStroke('7');

map=arr[7].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(seven,"action");

ActionMap actseven=arr[7].getActionMap();
actseven.put("action",actionListener);




KeyStroke eightKeyStroke.getKeyStroke('8');

map=arr[8].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(eight,"action");

ActionMap acteight=arr[8].getActionMap();
acteight.put("action",actionListener);




KeyStroke nineKeyStroke.getKeyStroke('9');

map=arr[9].getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

map.put(nine,"action");

ActionMap actnine=arr[9].getActionMap();
actnine.put("action",actionListener); 
La razon es :

By sharing an InputMap or ActionMap, any change to the shared InputMap or ActionMap will affect all components sharing the InputMap or ActionMap. WHEN_FOCUSED and WHEN_ANCESTOR_OF_FOCUSED_COMPONENT types of InputMaps can be shared. WHEN_IN_FOCUSED_WINDOW InputMaps cannot be shared.


Espero ha alguien le sirva

Última edición por abulon; 28/05/2008 a las 17:32 Razón: comentario