내 문제는 프레임 화면의 공간을 클릭하면 등록 된 키보드 키가 멈추어 져서 플레이어가 움직이지 않는 것입니다.JFrame 마우스 클릭 키보드 멈춤 키보드 버튼
도움을 미리 감사드립니다.
코드 :
private Component comp;
....
public InputManager(Component comp) {
this.comp = comp;
mouseLocation = new Point();
centerLocation = new Point();
// register key and mouse listeners
comp.addKeyListener(this);
comp.addMouseListener(this);
comp.addMouseMotionListener(this);
comp.addMouseWheelListener(this);
// allow input of the TAB key and other keys normally
// used for focus traversal
comp.setFocusTraversalKeysEnabled(false);
}
GUI 코드 :
Game game = new Game();
game.setMinimumSize(new Dimension(WIDTH * 2, HEIGHT * 2));
game.setPreferredSize(new Dimension(WIDTH * 2, HEIGHT * 2));
game.setMaximumSize(new Dimension(WIDTH * 2, HEIGHT * 2));
frame = new JFrame(Game.NAME);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(game);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
game.start();
+1 키 바인딩 용. +1을 리스너로 사용 중지하고 혼합 발언을 +1하십시오. 흠, 크레딧을주기 위해 두 개의 다른 포스트를 upvote해야합니까? – Robin
감사합니다. 덕분에 많은 도움이되었습니다. 나는 확실히 열쇠 바인딩을 시도 할 것이다. – DCSoft
임시 해결책을 찾았습니다. 게임 클래스를 JFrame 대신 InputManager 클래스에 전달했습니다. – DCSoft