//先增加一个侦听事件,btnOK为按钮
  btnOK.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(KeyEvent e) {
      btnOK_keyPressed(e);
    }
});
//
void btnOK_keyPressed(KeyEvent e) {
    if ((e.getSource() instanceof JButton) && (((JButton) e.getSource()).getActionCommand() == "确定")){
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        btnOK_actionPerformed(null);
      }
    }