import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*; //包含有Graphics2D类 这个类(画笔)可以设置旋转
public class Ellipse extends Applet implements Runnable
{
int AppletWidth,AppletHeight;
Ellipse2D E2D; //椭圆画笔
AffineTransform tans; //用于旋转
Thread thread;
Image OffScreen;//子画面 把子画面放在主画面上可以消去闪烁缺点
Graphics2D drawOffScreen;
public void inint()
{
this.setBackground(Color.black);
AppletWidth=getSize().width;
AppletHeight=getSize().height;
E2D=new Ellipse2D.Double(30,30,80,30);
tans=new AffineTransform();
OffScreen=createImage(AppletWidth,AppletHeight);
drawOffScreen=(Graphics2D)OffScreen.getGraphics();
}
public void start()
{
thread=new Thread(this);
thread.start();
}
public void stop()
{
thread=null;
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(OffScreen, 0, 0, this);
}
public void run()
{
while(true)
{
drawOffScreen.clearRect(0, 0, AppletWidth, AppletHeight);
drawOffScreen.setColor(Color.white);
tans.rotate(15.0*Math.PI/180, 70, 45);
drawOffScreen.setTransform(tans);
drawOffScreen.draw(E2D);
repaint();
try{
Thread.sleep(33);
}
catch(InterruptedException e){}
}
}
}