改进版——使用了双缓冲技术
import java.awt.*; import java.awt.event.*; public class DrawTurtle { private int x, y; public static void main(String[] args) { new DrawTurtle(); } public DrawTurtle() { x = 100; y = 10; Frame frame = new Frame("DrawTurtle"); DrawLittleTurtle turtle = new DrawLittleTurtle(); frame.add(turtle); frame.setSize(500, 500); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); turtle.requestFocus(); turtle.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_UP) { y -