I want to create a flying oval, but it doesn't work.

Source: Internet
Author: User

Import java. Applet .*;
Import java. AWT .*;
Import java. AWT. event .*;
Import java. AWT. Geom. *; // contains the graphics2d class. This class (paint brush) can be set to rotate.
Public class ellipse extends applet implements runnable
{
Int appletwidth, appletheight;
Ellipse2d e2d; // elliptical paint brush
Affinetransform Tans; // used for rotation
Thread thread;
Image offscreen; // place the sub-screen on the main screen to eliminate the flash disadvantage.
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 ){}
}
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.