JTextArea message = new JTextArea();
message.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent arg0) {
int key = arg0.getKeyCode();
if(key == '\n'){
JOptionPane.showMessageDialog(null,"您按下了回车");
}
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
}
});