brick breaker, bricks wont disappear
I figured out how to build my 2 dimensional array of bricks, now im having trouble so that when the ball hits the bricks i want it to decrease, i have the method hit brick and i think my problem is that im not telling the method that when the BALL hits the bricks i want it to decrease, am i right?

// AnimationPanel.java
//
// Informatics 45 Spring 2010
// Code Example: Our Ball Animation Becomes a Game
//
// This is relatively similar to our AnimationPanel in the previous version
// of our ball animation, with two changes:
//
// * The paddle is now drawn, in addition to just the ball.  For fun, I've
//   drawn the paddle in a different color than the ball.
//
// * This panel has a MouseMotionListener attached to it.  The job of a
//   MouseMotionListener is to listen for mouse movement within a component.
//   In this case, any mouse movement within our AnimationPanel will turn
//   into events, which we'll handle by adjusting the center x-coordinate
//   of the paddle accordingly.
//
// * Because we need to calculate a new position for the paddle as the mouse
//   moves, we'll need to be able to convert coordinates in both directions
//   (i.e., fractional coordinates to pixel coordinates and pixel coordinates
//   to fractional coordinates).

package inf45.spring2010.examples.animation2.gui;

import inf45.spring2009.examples.animation2.model.Animation;
import inf45.spring2009.examples.animation2.model.AnimationState;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class AnimationPanel extends JPanel
{
	private Animation animation;
	private inf45.spring2009.examples.animation2.model.AnimationState currentState;
	boolean brickVisible[][];
	int bricksInRow = 48; 
	int bricksInColumn = 8; 
	int brickWidth = 19; 
	int brickHeight = 13; 
	int bricksLeft ; 
	
	public AnimationPanel(Animation animation)
	{
		this.animation = animation;
		currentState = null;
		setBackground(Color.WHITE);
		
		addMouseMotionListener(
			new MouseMotionAdapter()
			{
				public void mouseMoved(MouseEvent e)
				{
					updatePaddlePosition(e.getX());
				}
			});
	}


	public void updateState(AnimationState newState)
	{
		currentState = newState;
	}
	
	
	private void updatePaddlePosition(int pixelX)
	{
		double paddleCenterX = convertPixelXToX(pixelX);
		animation.updatePaddleCenterX(paddleCenterX);
	}
	
	
	public void paint(Graphics g)
	{
		super.paint(g);
		
		if (currentState == null)
		{
			return;
		}
	
		

	
	     
		int centerPixelX = convertXToPixelX(currentState.getBallCenterX());
		int centerPixelY = convertYToPixelY(currentState.getBallCenterY());
		
		int radiusX = convertXToPixelX(currentState.getBallRadius());
		int radiusY = convertYToPixelY(currentState.getBallRadius());
		
		int topLeftPixelX = centerPixelX - radiusX;
		int topLeftPixelY = centerPixelY - radiusY;
		
		int paddleCenterPixelX = convertXToPixelX(currentState.getPaddleCenterX());
		int paddleCenterPixelY = convertYToPixelY(currentState.getPaddleCenterY());
		int paddleWidthPixels = convertXToPixelX(currentState.getPaddleWidth());
		int paddleHeightPixels = convertYToPixelY(currentState.getPaddleHeight());
		
		int paddleTopLeftPixelX = paddleCenterPixelX - (paddleWidthPixels / 2);
		int paddleTopLeftPixelY = paddleCenterPixelY - (paddleHeightPixels / 2);
		
		Graphics2D g2d = (Graphics2D) g;
		
		for (int x = 0;x<bricksInRow;x++){
		      for (int y = 0;y<bricksInColumn;y++){
		    	  brickVisible =new boolean[bricksInRow][bricksInColumn];
		    	    bricksLeft=0;
		      {
		          g2d.setColor(Color.red);
		          g2d.fillRect(x*brickWidth,y*brickHeight,brickWidth-1,brickHeight-1);
		        }
		  }
		 }
		
		//checks if ball hits a brick; if so resets x velocity and sets
		//brick to being hit; update score
			//ball = new Ball( x, y);
			
	 

		g2d.setRenderingHint(
			RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
		
		g2d.setColor(Color.BLUE);
		
		g2d.fillOval(topLeftPixelX, topLeftPixelY, radiusX * 2, radiusY * 2);

		g2d.setColor(Color.RED);
		
		
		g2d.fillRect(
			paddleTopLeftPixelX, paddleTopLeftPixelY,
			paddleWidthPixels, paddleHeightPixels);
		
		
	}
	  public void hitBrick(int x,int y, Graphics g) {
		    int nx,ny;
			Graphics2D g2d = (Graphics2D) g;

		    nx=(x/brickWidth);
		    ny=(y/brickHeight);

		    if ((nx<0)||(nx>=bricksInRow)||(ny<0)||(ny>=bricksInColumn)) return;

		    if (brickVisible[nx][ny]) {
		      brickVisible[nx][ny]=false;
		      bricksLeft--;
		      g2d.setColor(Color.black);
		      g2d.fillRect(nx*brickWidth,ny*brickHeight,brickWidth-1,brickHeight-1);
		    }
		  }    
	
	private int convertXToPixelX(double x)
	{
		return (int) (x * getWidth());
	}
	
	
	private int convertYToPixelY(double y)
	{
		return (int) (y * getHeight());
	}
	
	
	private double convertPixelXToX(int pixelX)
	{
		return (double) pixelX / getWidth();
	}
	
	
}

brick breaker, bricks wont disappear
===

I figured out how to build my 2 dimensional array of bricks, now im having trouble so that when the ball hits the bricks i want it to decrease, i have the method hit brick and i think my problem is that im not telling the method that when the BALL hits the bricks i want it to decrease, am i right?

// AnimationPanel.java
//
// Informatics 45 Spring 2010
// Code Example: Our Ball Animation Becomes a Game
//
// This is relatively similar to our AnimationPanel in the previous version
// of our ball animation, with two changes:
//
// * The paddle is now drawn, in addition to just the ball.  For fun, I've
//   drawn the paddle in a different color than the ball.
//
// * This panel has a MouseMotionListener attached to it.  The job of a
//   MouseMotionListener is to listen for mouse movement within a component.
//   In this case, any mouse movement within our AnimationPanel will turn
//   into events, which we'll handle by adjusting the center x-coordinate
//   of the paddle accordingly.
//
// * Because we need to calculate a new position for the paddle as the mouse
//   moves, we'll need to be able to convert coordinates in both directions
//   (i.e., fractional coordinates to pixel coordinates and pixel coordinates
//   to fractional coordinates).

package inf45.spring2010.examples.animation2.gui;

import inf45.spring2009.examples.animation2.model.Animation;
import inf45.spring2009.examples.animation2.model.AnimationState;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class AnimationPanel extends JPanel
{
	private Animation animation;
	private inf45.spring2009.examples.animation2.model.AnimationState currentState;
	boolean brickVisible[][];
	int bricksInRow = 48; 
	int bricksInColumn = 8; 
	int brickWidth = 19; 
	int brickHeight = 13; 
	int bricksLeft ; 
	
	public AnimationPanel(Animation animation)
	{
		this.animation = animation;
		currentState = null;
		setBackground(Color.WHITE);
		
		addMouseMotionListener(
			new MouseMotionAdapter()
			{
				public void mouseMoved(MouseEvent e)
				{
					updatePaddlePosition(e.getX());
				}
			});
	}


	public void updateState(AnimationState newState)
	{
		currentState = newState;
	}
	
	
	private void updatePaddlePosition(int pixelX)
	{
		double paddleCenterX = convertPixelXToX(pixelX);
		animation.updatePaddleCenterX(paddleCenterX);
	}
	
	
	public void paint(Graphics g)
	{
		super.paint(g);
		
		if (currentState == null)
		{
			return;
		}
	
		

	
	     
		int centerPixelX = convertXToPixelX(currentState.getBallCenterX());
		int centerPixelY = convertYToPixelY(currentState.getBallCenterY());
		
		int radiusX = convertXToPixelX(currentState.getBallRadius());
		int radiusY = convertYToPixelY(currentState.getBallRadius());
		
		int topLeftPixelX = centerPixelX - radiusX;
		int topLeftPixelY = centerPixelY - radiusY;
		
		int paddleCenterPixelX = convertXToPixelX(currentState.getPaddleCenterX());
		int paddleCenterPixelY = convertYToPixelY(currentState.getPaddleCenterY());
		int paddleWidthPixels = convertXToPixelX(currentState.getPaddleWidth());
		int paddleHeightPixels = convertYToPixelY(currentState.getPaddleHeight());
		
		int paddleTopLeftPixelX = paddleCenterPixelX - (paddleWidthPixels / 2);
		int paddleTopLeftPixelY = paddleCenterPixelY - (paddleHeightPixels / 2);
		
		Graphics2D g2d = (Graphics2D) g;
		
		for (int x = 0;x<bricksInRow;x++){
		      for (int y = 0;y<bricksInColumn;y++){
		    	  brickVisible =new boolean[bricksInRow][bricksInColumn];
		    	    bricksLeft=0;
		      {
		          g2d.setColor(Color.red);
		          g2d.fillRect(x*brickWidth,y*brickHeight,brickWidth-1,brickHeight-1);
		        }
		  }
		 }
		
		//checks if ball hits a brick; if so resets x velocity and sets
		//brick to being hit; update score
			//ball = new Ball( x, y);
			
	 

		g2d.setRenderingHint(
			RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
		
		g2d.setColor(Color.BLUE);
		
		g2d.fillOval(topLeftPixelX, topLeftPixelY, radiusX * 2, radiusY * 2);

		g2d.setColor(Color.RED);
		
		
		g2d.fillRect(
			paddleTopLeftPixelX, paddleTopLeftPixelY,
			paddleWidthPixels, paddleHeightPixels);
		
		
	}
	  public void hitBrick(int x,int y, Graphics g) {
		    int nx,ny;
			Graphics2D g2d = (Graphics2D) g;

		    nx=(x/brickWidth);
		    ny=(y/brickHeight);

		    if ((nx<0)||(nx>=bricksInRow)||(ny<0)||(ny>=bricksInColumn)) return;

		    if (brickVisible[nx][ny]) {
		      brickVisible[nx][ny]=false;
		      bricksLeft--;
		      g2d.setColor(Color.black);
		      g2d.fillRect(nx*brickWidth,ny*brickHeight,brickWidth-1,brickHeight-1);
		    }
		  }    
	
	private int convertXToPixelX(double x)
	{
		return (int) (x * getWidth());
	}
	
	
	private int convertYToPixelY(double y)
	{
		return (int) (y * getHeight());
	}
	
	
	private double convertPixelXToX(int pixelX)
	{
		return (double) pixelX / getWidth();
	}
	
	
}
