★ wanayoo — archive 1999 http://javaboutique.webdeveloper.com/tutorials/Java_by_Example/section7_4.htmlNouvelle recherche | Portail wanayoo
80211 Planet

100's of firms that help your Web site be found


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Hacker's Secrets
Find a Web HostFind a Web Host
Promote Your Website
Build an Online Store
IT Training
Track Defects Online
Reach IT Professionals
Shop For Computers
Register Domains
Software Store
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:



Tutorials : Java by Example : Section 7 :
Section Seven Contents
Fun With Letters and Words
Rotating Lines and Polygons
Sorting and Shuffling

Letters - Words - Lines - Shuffle

Rotating Lines and Polygons - Rotating

To rotate things, we need to convert polar to cartesian coordinates:
x = r * Math.cos(theta); and y = r * Math.sin(theta);
Polar coordinates (r, theta) are just another way of specifying points in a 2D plane, where r represents the distance of a point from the center and theta the angle from the horizontal axis (x-axis) through the center. The following applet shows this principle in a minimized form, it rotates a hand around the center and displays the angle accordingly.

//Sourcecode

import java.awt.*;
import java.applet.*;

public class Project40 extends Applet implements Runnable
{
    Thread runner;
    Image Buffer;
    Graphics gBuffer;
    int angle;

    public void init()
    {
        //create graphics buffer, the size of the applet
        Buffer=createImage(size().width,size().height);
        gBuffer=Buffer.getGraphics();
    }

    public void start()
    {
        if (runner == null)
        {
            runner = new Thread (this);
            runner.start();
        }
    }

    public void stop()
    {
        if (runner != null)
        {
            runner.stop();
            runner = null;
        }
    }

    public void run()
    {
        while(true)
        {
            try {runner.sleep(250);}
            catch (Exception e) { }

            repaint();
        }
    }

    void drawStuff()
    {
        //paint background black
        gBuffer.setColor(Color.black);
        gBuffer.fillRect(0,0,size().width,size().height);

        //get the center of the applet
        Point p=new Point(size().width/2, size().height/2);
        //define the hand length
        int LENGTH=70;

        //calculate the vector, using the constant Pi
        double vector = angle * Math.PI*2 / 360.0;

        int vx=(int)(p.x+LENGTH*Math.sin(vector));
        int vy=(int)(p.y-LENGTH*Math.cos(vector));

        gBuffer.setColor(Color.yellow);
        //the hand
        gBuffer.drawLine(p.x, p.y, vx, vy);
        //the round "axis"
        gBuffer.drawOval(p.x-6,p.y-6,12,12);

        //display the angle in degrees
        gBuffer.setFont(new Font("Helvetica",Font.PLAIN,13));
        gBuffer.drawString("Angle="+angle+"°",10,20);

        //increase the angle, to move the hand
        if(angle<360)
            angle++;
        else
            angle=0;
    }

    public void update(Graphics g)
    {
        paint(g);
    }

    public void paint(Graphics g)
    {
        drawStuff();
        g.drawImage (Buffer,0,0, this);
    }
}

internet.com logo














WebDev News

JBoss Group: Defections Aren't a Big Deal

IE Object Tag Buffer Overflow Patched

SCO Shuts Down German Site





JWizardPane
Build modern wizard style interface quickly. API easy to use. Bulti-in show dialog and frame support.
Download of the Week
BSCOutline v5.10
BSCOutline Java Outline Applet is a customizable tree view control for use in Web pages, similar to that used by Windows File Manager or Explorer. BSCOutline has been written to be the simple to use and small to store.

JB User Poll
As a JavaBoutique Reader what kind of articles do you prefer?
The JavaBoutique Top 15:
1. ChompText
2. RushHour
3. PulseText
4. PingPong
5. DJPopMenu
6. NavBar
7. 3DMaze
8. Encyclo
9. AnimLetters_anim
10. AScroll2
11. Nibbly
12. SonaliCalendar
13. BMMenu
14. BMI
15. SlideMenu
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Verizon Ordered to Reveal Names of Music Pirates
The U.S. Court of Appeals Wednesday afternoon rejected Verizon's for request for a stay in earlier court ruling ordering the telecom giant to turn over the names of two subscribers suspected of illegally downloading copyrighted music.

E-mail Archiving Emerges as Critical Function
In today's corporate world, e-mail holds a company's critical information. Now a growing number of businesses are realizing that they need to save these e-mails. And they just can't pack them away like receipts you toss in a box at home.

The Deadly Duo: Spam and Viruses, May 2003
Spam attacks increase another 6+% for the month, as the global ratio of unwanted messages in business e-mail breaks the 50% mark.


The Event for Search Engine Marketing & Optimization

Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/