0

please help. I am creating a breakout game and I'm trying to build the brick class which diplays an image of a brick layer by layer.But my code compiles but nothing shows up. This is what i have so far. Main Class:

public class Breakout extends Applet implements Runnable{
Thread thread = new Thread(this);
boolean running = true;
Brick b;
Image dbImage;
Graphics dbg;
public void init(){
    setSize(800,600);
    b = new Brick();
}
public void start(){
    thread.start();
}
public void destroy(){
    running = false;
}
public void stop(){
    running = false;
}
public void run(){
    while(running){
        b.update(this);
        repaint();
        try{
            thread.sleep(20);
        }
        catch (InterruptedException e){
            System.out.println("AN ERROR HAS OCCURED");
        }
    }
}
public void update(Graphics g){
    dbImage = createImage(getWidth(),getHeight());
    dbg = dbImage.getGraphics();
    paint(dbg);
    g.drawImage(dbImage,0,0,this);
}
public void paint(Graphics g){
    b.paint(g,this);
}   
}

This is the brick class:

public class Brick {
private URL url;
private Image brick;
 Image [][] bricks = new Image[50][3];
public void brick (Breakout bR){
    url = bR.getDocumentBase();
    brick = bR.getImage(url,"brick.png"); 
    for(int i =0; i < bricks.length; i++)
       for(int j = 0; j < bricks[0].length; j++)
           bricks[i][j] = brick;

}

public void update(Breakout bR){

}

public void paint(Graphics g, Breakout bR){

    int imageWidth = bricks[0][0].getWidth(bR);
    int imageHeight = bricks[0][0].getHeight(bR);
    for (int i = 0; i < bricks.length; i++)
        for ( int j =0; j < bricks[0].length; j++)

            g.drawImage(bricks[i][j], i * imageWidth + 5, j * imageHeight + 5, bR);

}
}

Thanks for your help.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
matt
  • 11
  • 4
  • I think it has to do something with the paint method in the brick class but i am not sure – matt May 23 '16 at 00:16
  • 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson May 23 '16 at 04:16

0 Answers0