Hey everyone I'm trying to make a brick wall and every second row has to be offset by half of the brick width. I don't know why my program isn't displaying anything all it shows is the grey background.This is my panel class
import java.awt.*; import javax.swing.*; public class BrickWall extends JPanel { private final int BRICK_WIDTH = 50; private final int BRICK_HEIGHT = 25; public BrickWall() { setPreferredSize(new Dimension(500,500)); setBackground(Color.darkGray); } public void PaintComponent(Graphics page) { super.paintComponent(page); int x,y; x=0; y=0; int xOffset = -1*(BRICK_WIDTH/2); int yOffset= BRICK_HEIGHT+y; int rows = 0; int rowLength = getWidth(); while(x<=rowLength) { page.setColor(Color.red); page.fillRect(x, y, BRICK_WIDTH,BRICK_HEIGHT ); x+=52; if(rows%2==1) { page.setColor (Color.red); page.fillRect (x, y, BRICK_WIDTH,BRICK_HEIGHT ); x+=52; } if(x==getWidth()) { x=0; y +=27; rows++; } } } }
This is my driver class
import javax.swing.*; import java.awt.*; public class BrickDriver { public static void main(String[] args) { JFrame frame = new JFrame ("Brick Wall"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); BrickWall panel = new BrickWall(); frame.getContentPane().add(panel); frame.pack (); frame.setVisible (true); } }
This is my first time dealing with GUIs so there could be a big problem.