我准备做一个JAVA小游戏,在游戏中要实现一只移动的小狗(自动移动的)
但是我不清楚怎样用JAVA画狗
请那位高手指点一下~
谢谢先~~~
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Graphics;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.*;
import java.awt.image.*;
import sun.audio.*;
import java.lang.System;
import java.util.*;
import java.applet.AudioClip;
public class TestDrawFlc extends Frame
{
static TestDrawFlc m_Draw;
java.util.Timer timer;
int x=30;
private Dimension offDimension;
private Image offImage;
private Graphics offGraphics;
public TestDrawFlc(String Title)
{
super(Title);
setSize(800,600);
timer = new java.util.Timer();
TimerTask task = new MyTask();
timer.schedule(task,30,30);
}
public void paint(Graphics g)
{
}
public void update(Graphics g)
{
Dimension d = size();
if ((offGraphics == null) || (d.width != offDimension.width)
|| (d.height != offDimension.height))
{
offDimension = d;
offImage = createImage(d.width, d.height);
offGraphics = offImage.getGraphics();
}
offGraphics.setColor(new Color(255,255,255));
offGraphics.fillRect(0,0,800,800);
offGraphics.setColor(new Color(255,0,0));
offGraphics.fillRect(x,30,80,80);
x+=3;
if(x>800)
{
x=30;
}
g.drawImage(offImage, 0, 0, null);
}
public static void main(String[] args)
{
m_Draw=new TestDrawFlc("动画研究程序");
m_Draw.pack();
m_Draw.show();
m_Draw.repaint();
}
}
class MyTask extends TimerTask
{
public void run()
{
TestDrawFlc.m_Draw.repaint();
}
}
~~ 这个程序希望能有点帮助!!
名字不过是个代号而已!~!又何必太在意呢!!