I think I got it working. I put a keyListener on the mainFrame to the class ListenForKeys and method keyTyped(KeyEven ke)
It looks like this (and yes I know this is repetitive but it was an easy solution):
class ListenForKeys extends KeyAdapter { public void keyTyped(KeyEvent ke) { char keyChar = ke.getKeyChar(); String key = Character.toString(keyChar); if(key.equals("0")) { JButton b = mainButtonList.get(9); b.doClick(); } else if(key.equals("1")) { JButton b = mainButtonList.get(6); b.doClick(); } else if(key.equals("2")) { JButton b = mainButtonList.get(7); b.doClick(); } else if(key.equals("3")) { JButton b = mainButtonList.get(8); b.doClick(); } else if(key.equals("4")) { JButton b = mainButtonList.get(3); b.doClick(); } else if(key.equals("5")) { JButton b = mainButtonList.get(4); b.doClick(); } else if(key.equals("6")) { JButton b = mainButtonList.get(5); b.doClick(); } else if(key.equals("7")) { JButton b = mainButtonList.get(0); b.doClick(); } else if(key.equals("8")) { JButton b = mainButtonList.get(1); b.doClick(); } else if(key.equals("9")) { JButton b = mainButtonList.get(2); b.doClick(); } else if(key.equals("+")) { JButton b = operators.get(0); b.doClick(); } else if(key.equals("-")) { JButton b = operators.get(1); b.doClick(); } else if(key.equals("x")||key.equals("*")) { JButton b = operators.get(2); b.doClick(); } else if(key.equals("/")) { JButton b = operators.get(3); b.doClick(); } System.out.println(key); } }
One problem though... how do I register a keyStroke for the ENTER key? The VK_ENTER key code doesn't seem to work... it just keeps adding line breaks in the console.