- import java.awt.event.*; import acm.program.GraphicsProgram;
- import acm.graphics.*;
- @SuppressWarnings("serial")
- public class move extends GraphicsProgram{
- public void init(){
- m=new GRect(50,50,100,100);
- add(m);
- addKeyListeners();
- }
- public void keyPressed(KeyEvent e){
- int s=e.getKeyCode();
- if(s==KeyEvent.VK_DOWN){
- m.move(10,0);
- }
- if(s==KeyEvent.VK_UP){
- m.move(0,10);
- }
- }
- private GRect m; }
复制代码 |