chuxueaihaozhe
发贴: 26
积分: 0
|
于 2005-08-26 16:51
import java.awt.*; import java.applet.Applet; import javax.swing.*;
public class Pintu1 extends Applet { final int IMAGE_WIDTH = 120; final int IMAGE_HEIGHT= 120; final int NO_IMAGE = -1; int m_nImageNo[][] ; final int DELTAX = 120; Image[] m_image = new Image[9]; Image m_imagAll ;
public void initData() { for(int i= 0;i<3;i++) { for(int j=0;j<3;j++) { m_nImageNo[i][j]=j*3+i; } } m_nImageNo[1][2]=NO_IMAGE; m_nImageNo[1][1]=7; }
public void init() { MediaTracker mediaTracker = new MediaTracker(this); m_imagAll = getImage(getCodeBase(),"pintu.JPG"); mediaTracker.addImage(m_imagAll,0); try { mediaTracker.waitForAll(); } catch(Exception e) { System.out.println("图片装载出错"); }
for(int i=0;i<9;i++) { m_image[i] = createImage(IMAGE_WIDTH,IMAGE_HEIGHT); m_image[i] = getImage(getCodeBase(),i+".JPG"); Graphics g = m_image[i].getGraphics(); mediaTracker.addImage(m_image[i],i+1); try { mediaTracker.waitForAll(); } catch(Exception e) { System.out.println("图片装载出错"); } initData(); } }
public void paint(Graphics g) { g.setColor(Color.blue); for(int i = 0;i<3;i++) { for(int j = 0;j<3;j++) { int x =i*IMAGE_WIDTH + DELTAX; int y =j*IMAGE_HEIGHT; if(m_nImageNo[i][j] == NO_IMAGE) g.fill3DRect(x,y,IMAGE_WIDTH,IMAGE_HEIGHT,true); else { g.drawImage(m_image[m_nImageNo[i][j]],x,y,this); } } } for(int i=0;i<3;i++) { int nRow = i%3; int nCol = i/3; g.drawImage(m_imagAll,0,0,IMAGE_WIDTH,IMAGE_HEIGHT, nRow*IMAGE_WIDTH,nCol*IMAGE_HEIGHT, (nRow+1)*IMAGE_WIDTH,(nCol+1)*IMAGE_HEIGHT,this); } }
public Pintu1() {}; } ================================ <HTML> <heard>
</heard> <body>
<applet code ="Pintu1.class" width="480" height="360"> </applet> </body> </HTML> ========================= 请网友帮帮忙,看是什么原因.谢谢!
|