Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用按键时如何在同一位置移动椭圆和矩形_Java_Swing_Awt - Fatal编程技术网

Java 使用按键时如何在同一位置移动椭圆和矩形

Java 使用按键时如何在同一位置移动椭圆和矩形,java,swing,awt,Java,Swing,Awt,我想在同一位置上移动椭圆和矩形。然而,当我按下向左箭头和向上箭头时,椭圆形在错误的位置。谁能帮我一下吗 使用AffineTransform反转图形,如需更快更好的帮助,请发布或。 int keyboardPress = keyboard.getKeyCode(); if(keyboardPress == KeyEvent.VK_RIGHT){ xLocation += 30; xLocationEyes

我想在同一位置上移动椭圆和矩形。然而,当我按下向左箭头和向上箭头时,椭圆形在错误的位置。谁能帮我一下吗


使用
AffineTransform
反转
图形
,如需更快更好的帮助,请发布或。
         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();
         }