How do I call Graphics Method inside KeyListener?

前端 未结 2 604
被撕碎了的回忆
被撕碎了的回忆 2021-01-24 07:41

Ahead of time, I would like to say there have been many posts similar to this, however, none of them apply to me or none of them actually have any answer at all, and are outdate

2条回答
  •  忘掉有多难
    2021-01-24 08:06

    OK! I actually figured it out by myself! What I did is called the g2d.rotate(.....) inside my draw() method. What I did is created variables that check for rotation, and set them true or false inside of my KeyPressed() method. Here is the code I used inside the draw() method:

     if(isRotatingPositive == true) {
        g2d.rotate(Math.toRadians(speed));
     } else if(isRotatingNegative == true) {
        g2d.rotate(Math.toRadians(-speed));
     }
    

提交回复
热议问题