importjava.applet.*;importjava.awt.*;publicclassBallextendsAppletimplementsRunnable{intx=0;inty=0;Threadt;Imagebuffer;Graphicsbufferg;publicvoidinit(){t=newThread(this);t...
import java.applet.*;import java.awt.*;
public class Ball extends Applet implements Runnable
{
int x = 0;
int y = 0;
Thread t;
Image buffer;
Graphics bufferg;
public void init()
{
t = new Thread(this);
t.start();
Dimension d = getSize();
buffer = createImage(d.width, d.height);
}
public void run() {
try
{
while(true)
{
repaint();
Thread.sleep(200);
}
}
catch(Exception e) {}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(bufferg == null)
bufferg = buffer.getGraphics();
Dimension d = getSize();
bufferg.setColor(Color.white);
bufferg.fillRect(0, 0, d.width, d.height);
bufferg.setColor(Color.blue);
bufferg.fillOval(x, y, 30, 30);
g.drawImage(buffer, 0,0, this);
x += 9;
y += 12;
if((y + 30) > d.height&&(x+30)>=300)
{
x +=12;
y -=9;
}
if((x +30) > d.width&&(y+30)>=75)
{
x -=9;
y -=12;
}
if((y -30) < 0&&x<=243)
{
y =0;
x =0;
}
}
}
希望球弹出后又从最初的点,再弹一遍
总体画面是400x400,所有的三角形都是3,4,5的近似三角形
谢谢你, 不好意思, 要用双缓冲的方法
展开