エンターキーをJbutton上において押下したときでも、ボタンのアクションを呼び出したいのですが、
どうしたらいいでしょうか?
KeyListenerをimplementsして、下記のようにしたのですが、
JButton okButton = new JButton("OK");
okButton.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
System.out.println("エンター");
}
}
});
エラーが出ます。
The method addKeyListener(KeyListener) in the type Component is not applicable for the arguments (new KeyAdapter(){})