如何从另一个班级调出图像?

时间:2016-05-23 00:15:16

标签: java image class applet awt

请帮忙。我正在创建一个突破性的游戏,我正在尝试构建一个砖层,逐层渲染砖块的图像。但是我的代码编译但没有任何显示。 这就是我到目前为止所拥有的。 主类:

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);
}   
}

这是砖类:

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);

}
}

感谢您的帮助。

0 个答案:

没有答案