Rectangle from array is not drawing

37 Views Asked by At

I am making a brick breaker game in Java NetBeans 6.9.1. My array map/rectangle is not drawing like it should be. I have no idea what is the problem.

Main Class:

  public static void main(String[] args) {
   JFrame obj = new JFrame();
   GamePlay gamePlay = new GamePlay();
   obj.setBounds (10, 10, 700, 600);
   obj.setTitle("Brick Breaker");
   obj.setResizable(false);
   obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   obj.setVisible(true);
   obj.add(gamePlay);

MapGenerator:

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
public class MapGenerator {
public int map[][];
public int brickWidth;
public int brickHeight;
public MapGenerator(int row, int col){
    map = new int [row][col];
    for (int i = 0; i< map.length;i++) {
        for (int j=0; j< map[0].length; j++) {
            map[i][j] = 1;
        }
    }
    brickWidth = 540/col;
    brickHeight = 150/row;
}
public void draw(Graphics2D g){
    for(int i = 0; i < map.length; i++) {
        for(int j=0; j< map[0].length; j++){
            if (map[i][j]>0){
               g.setColor(Color.red);
               g.fillRect(j * brickWidth + 80, i *brickHeight + 50,       brickWidth, brickHeight);

Drawing the map in GamePlay class:

private MapGenerator map;
 public GamePlay() {
    map = new MapGenerator(3,7);
    //drawing map
    map.draw((Graphics2D)g);
0

There are 0 best solutions below