Find us on Google+ Kill the code: Windmill effect in Java Applet

Thursday, 12 July 2012

Windmill effect in Java Applet




Code:


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication2;

import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.lang.Math;

/**
 *
 * @author zero
 */
public class NewApplet extends Applet implements Runnable {
    Dimension d = getSize();
    int b = 200;
    int c = 200;
    int a = 0;
    int x = (int)(100 * Math.cos(Math.toRadians(a)));
    int y = (int)(100 * Math.cos(Math.toRadians(a)));
    int i = 1;
    public void run() {
        while(true) {
         
            for(i = 90; i >= 0; i--) {
                try {
                Thread.sleep(5);
                }
                catch(Exception e) {
                }
                a = i;
                x = (int)(100 * Math.cos(Math.toRadians(a)));
                y = (int)(100 * Math.sin(Math.toRadians(a)));
                //showStatus(x + "," + y);
                repaint();
            }
        }
    }

    /**
     * Initialization method that will be called after the applet is loaded into
     * the browser.
     */
    public void init()
        Thread t = new Thread(this);
        t.start();
    }
 
    public void paint(Graphics g) {
        g.drawLine(b, c, b, c + 200);
        g.drawLine(b, c, b + x, c + y);
        g.drawLine(b, c, b - x, c - y);
        g.drawLine(b, c, c + y, b - x);
        g.drawLine(b, c, c - y, b + x);
        //g.drawRect(0, 0, 550, 550);
    }
 
    // TODO overwrite start(), stop() and destroy() methods
}

No comments:

Post a Comment