rendered paste bodypackage test;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.Random;class Circle extends Rectangle { public Circle (int x, int y, int r) { super(x - r, y - r, r * 2, r * 2); } public void draw (Graphics g) { g.setColor(Color.BLACK); g.fillRect(x, y, width, height); }}class Vector{ public int xCom; public int yCom; public Vector(int x, int y) { xCom = x; yCom = y; }}public class Bounce extends JPanel implements Runnable, ActionListener { private Circle ball; JFrame f; Random r; Vector v; Timer t; public Bounce () { super(); f = new JFrame("Bounce"); ball = new Circle(50, 50, 5); r = new Random(System.nanoTime()); v = new Vector(1,1); } public void paintComponent (Graphics g) { ball.draw(g); } public void run () { this.setPreferredSize(new Dimension(100, 100)); f.setContentPane(this); f.pack(); f.setVisible(true); t = new Timer(10, this); t.start(); } private void update () { ball.x += v.xCom; ball.y += v.yCom; if(ball.x >= this.getWidth()-ball.width || ball.x <= ball.width) v.xCom = -v.xCom; if(ball.y >= this.getHeight()-ball.height || ball.y <= ball.height) v.yCom = -v.yCom; } public void actionPerformed (ActionEvent e) { update(); f.repaint(); } public static void main (String [] args) { SwingUtilities.invokeLater(new Bounce()); }}