import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; public class BouncingBallsWithRebound // this class is the same as BouncingBalls but adds to actionPerformed a little code, so the comments here focus just on the changes { public static void main(String[] args) { JFrame frame=new JFrame(); frame.setSize(540,540); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsPanel gp=new GraphicsPanel(); frame.add(gp); frame.setVisible(true); } public static class GraphicsPanel extends JPanel implements ActionListener { private BouncingBall[] balls; private int number; private Random generator; public GraphicsPanel() { number=25; generator=new Random(); balls=new BouncingBall[25]; for(int i=0;i