import java.applet.Applet;
import java.awt.Graphics;
class ImageTest extends Applet
{
Image[] MyPicture ;
Image offScreenIma;
Graphics GraphicsIma;
public void init()
{
MyPictrue=new Image[10];
//Image ImageBeauty;
offScreenIma=createImage(getSize().width,getSize().heigth);
GraphicsIma=offScreenIma.getGraphics();
for(int i=0;i <MyPicture.length;i++)
{
MyPicture[0]=getImage(getDocumentBase(),parseString(i)+ ".jpg ");
GraphicsIma.drawImage(MyPicture[i],100,100,this);
}
void paint(Graphics g)
{
g.drawImage(offScreenIma,100,100,this);
}
}
------解决方案--------------------
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.*;
class ImageTest extends Applet
{
Image[] MyPicture ;
Image offScreenIma;
Graphics GraphicsIma;
public void init()
{
MyPicture=new Image[10];
//Image ImageBeauty;
offScreenIma=createImage(getSize().width,getSize().height);
GraphicsIma=offScreenIma.getGraphics();
for(int i=0;i <MyPicture.length;i++)
{
MyPicture[0]=getImage(getDocumentBase(), "example "+i+ ".jpg ");
GraphicsIma.drawImage(MyPicture[i],100,100,this);
}
}
public void paint(Graphics g)
{
g.drawImage(offScreenIma,100,100,this);
}
}
你的错有点多哦,包也没导入完,就开始用包中的方法了。简单修改了下
------解决方案--------------------
你要达到动画的效果,可以加入线程嘛
假设你有15幅图片,你可以再加入这些代码,实现你动画的效果
public void start()
{
mythread=new Thread(this);
mythread.start();
}
public void stop()
{
mythread=null;
}
public void run()
{
while(true)
{
if(count> 15)
count=0;
repaint();
count++;
try{ mythread.sleep(200);
}
catch(InterruptedException e){}
}
}
public void paint(Graphics g) //再把paint方法改下
{ if((MyPicture[count])!=null)
g.drawImage(offScreenIma,100,100,this);
}
------解决方案--------------------
方法一:一般方法
import java.applet.*;
import java.awt.*;
import java.awt.Graphics;
public class ShowImage extends Applet {
private int currentImage;
private int totalImage=10;
private Image[] images=new Image[totalImage];
public void init(){
for(int i=0;i <10;i++)
images[i]=getImage(getDocumentBase(), "T "+(i+1)+ ".gif ");
}
public void paint(Graphics g){
g.drawImage(images[currentImage], 30,20,this);
currentImage=++currentImage%10;
try {
Thread.sleep(500);
}
catch (Exception ex) {
ex.printStackTrace();
}
repaint();
}
public void start(){
currentImage=0;
}
}
方法二:使用双缓冲
import java.applet.*;
import java.awt.*;
import java.awt.Graphics;
public class DoubleBuffer extends Applet {
private int currentImage;
private int totalImage=10;
private Image[] images=new Image[totalImage];