日期:2014-05-20 浏览次数:20738 次
import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JEditorPane; import javax.swing.JFrame; public class A extends JFrame { public static void main(String[] args) { A a = new A(); a.setVisible(true); JEditorPane p = new JEditorPane(); a.add(p); p.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { int kc = arg0.getKeyCode(); if (kc == KeyEvent.VK_UP || kc == KeyEvent.VK_DOWN|| kc == KeyEvent.VK_LEFT|| kc ==KeyEvent.VK_RIGHT) { arg0.consume(); } } @Override public void keyReleased(KeyEvent arg0) { int kc = arg0.getKeyCode(); if (kc == KeyEvent.VK_UP || kc == KeyEvent.VK_DOWN|| kc == KeyEvent.VK_LEFT|| kc ==KeyEvent.VK_RIGHT) { arg0.consume(); } } @Override public void keyTyped(KeyEvent arg0) { int kc = arg0.getKeyCode(); if (kc == KeyEvent.VK_UP || kc == KeyEvent.VK_DOWN|| kc == KeyEvent.VK_LEFT|| kc ==KeyEvent.VK_RIGHT) { arg0.consume(); } } }); } }