Java Bouncing Ball

前端 未结 4 1647
天涯浪人
天涯浪人 2020-11-22 04:57

I am trying to write a Java application which draws multiple balls on screen which bounce off of the edges of the frame. I can successfully draw one ball. However when I add

4条回答
  •  星月不相逢
    2020-11-22 05:41

    You need to use two completely distinct classes here -- one for BallContainer which extends JPanel and is the component that draws the Balls, and another for Ball which does not extend anything but rather holds the coordinates and Color of a Ball. BallContainer should hodl a List that it iterates through when it moves them and when it paints them.

提交回复
热议问题