So I have this bit of code, not complete but can give you complete code if needed, and so far, it makes a few shapes which is great and all but I need it to delete shapes on request. I want to make a brick game and basically I will edit this code so the ball bounces off the walls and hits bricks but before I do this I want to know how to at the very least know how to delete these shapes that I made so I can then use that code to practice making a brick game that will delete multiple elements.
Long story short, I want to know how to make the squares disappear. The only thing I've heard so far is to set what I want equal to NULL, but I'm not sure how to do it.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package bouncing.ball; /** * * @author Marlin */ import javax.swing.*; import java.awt.*; public class BouncePanel extends JPanel { //location of bouncing ball private int x; private int y; private int dx = 5; private int dy = 5; BouncePanel() { x = 100; y = 50; AnimationThread animethread = new AnimationThread(this); animethread.start(); } public void paintComponent(Graphics g) { //first, clear screen super.paintComponent(g); g.drawLine(10, 20, 300, 200); g.drawRect(100, 100, 50, 70); g.setColor(Color.BLUE); g.fillOval(x, y, 40, 40); } public void update() throws InterruptedException { dy += 1; x += dx; y += dy; if (x < 0) { x = 0; dx = -dx; } if (x + 40 >= getWidth()) { dx = -dx; } if (y < 0) { y = 0; dy = -dy; } if (y + 40 >= getHeight()) { dy = -dy; } repaint(); } }