使用按键时如何将椭圆和矩形移动到相同位置

时间:2016-02-12 00:50:19

标签: java swing awt

我想将椭圆和矩形移动到同一位置。然而,当我按下左箭头和向上箭头时,椭圆形位于错误的位置。任何人都可以帮我这个。

pacman1 pacman

         int keyboardPress = keyboard.getKeyCode();
         if(keyboardPress == KeyEvent.VK_RIGHT){
             xLocation += 30;
             xLocationEyes += 30;
             angle = 45;
             repaint();
         }
         else if(keyboardPress == KeyEvent.VK_LEFT){
             if(xLocation == xrandomLocation + 40){

             }
             angle = -145;
             xLocation -= 30;
             xLocationEyes -= 30;
             repaint();
         }
         else if(keyboardPress == KeyEvent.VK_DOWN){
             angle = -45;
             yLocation += 30;
             yLocationEyes += 30;
             repaint();
         }
         else if(keyboardPress == KeyEvent.VK_UP){
             angle = -235;
             yLocation -= 30;
             yLocationEyes -= 30;
             repaint();
         }

0 个答案:

没有答案