Find us on Google+ Kill the code: javac
Showing posts with label javac. Show all posts
Showing posts with label javac. Show all posts

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
}

Thursday, 8 March 2012

Draw Table with required rows and cols in JAVA



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


/*
<applet code="mousemotion" width=400 height=400>
</applet>
*/


public class mousemotion extends Applet implements MouseMotionListener,MouseListener {
String name="NISARG";
//String dim=" ";
int mx,my,mx2,my2,mx1,my1,mx3,my3;
int reles=0,dragged=0,drg_reles=0,rls_aftr_drg=0,clr_screen=0;
int ROW=12;
int COLOUM=12;



public void init() {
addMouseMotionListener(this);
addMouseListener(this);
}
public void mouseClicked(MouseEvent me) {
showStatus("MOUSE CLICKED.");
clr_screen=1;
repaint();
}
public void mousePressed(MouseEvent me) {
mx1=me.getX();
my1=me.getY();
}
public void mouseEntered(MouseEvent me) {
showStatus("SHOW STATUS.");
}
public void mouseReleased(MouseEvent me) {
if(dragged==1) {
drg_reles=1;
}
mx2=me.getX();
my2=me.getY();
dragged=0;
reles=1;
repaint();
}
public void mouseExited(MouseEvent me) {
showStatus("MOUSE EXITED.");
}
public void mouseDragged(MouseEvent me) {
showStatus("Mouse is at "+me.getX()+" "+me.getY());
mx3=me.getX();
my3=me.getY();
rls_aftr_drg=1;
//drg_reles=1;
dragged=1;
repaint();
}
public void mouseMoved(MouseEvent me) {
showStatus("Mouse is at "+me.getX()+" "+me.getY());
}
public void paint(Graphics g) {
if(clr_screen==1) {
clr_screen=0;
}
else if(reles==1 && dragged==1) { //MOUSE RELEASED.
g.drawLine(mx1,my1,mx2,my1);
g.drawLine(mx1,my1,mx1,my2);
g.drawLine(mx1,my2,mx2,my2);
g.drawLine(mx2,my1,mx2,my2);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;

}
//g.drawLine(mx1,ROW11,mx3,ROW11);
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
reles=0;
}
else if(rls_aftr_drg==1) { //MOUSE DRAGGED.
g.drawLine(mx1,my1,mx3,my1);
g.drawLine(mx1,my1,mx1,my3);
g.drawLine(mx1,my3,mx3,my3);
g.drawLine(mx3,my1,mx3,my3);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;

}
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
dragged=0;
//rls_aftr_drg=0;
}
if(drg_reles==1) { //MOUSE RELEASED.
g.drawLine(mx1,my1,mx2,my1);
g.drawLine(mx1,my1,mx1,my2);
g.drawLine(mx1,my2,mx2,my2);
g.drawLine(mx2,my1,mx2,my2);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;

}
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
drg_reles=0;
}
}
}

Saturday, 25 February 2012

Moving Circle in JAVA

An applet program to move circle in JAVA

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

/*
  <applet code="moving_circle" width=300 height=100>
  </applet>
*/

public class moving_circle extends Applet implements Runnable
{
    int x=0;
    Thread t;
    Image buffer;
    Graphics bufferg;

    public void init()
    {
        t=new Thread(this);
        t.start();
        Dimension d=getSize();
        buffer=createImage(d.width,d.height);
    }
    public void run()
    {
        try
        {
            while(true)
            {
               repaint();
               Thread.sleep(500);
            }
        }
        catch(Exception e)
        {
        }
    }

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

    public void paint(Graphics g)
    {
        if(bufferg==null)
            bufferg=buffer.getGraphics();

        Dimension d=getSize();
        bufferg.setColor(Color.black);
        bufferg.fillRect(0,0,d.width,d.height);
        bufferg.setColor(Color.white);
        bufferg.fillOval(x,d.height/4,50,50);

        g.drawImage(buffer,0,0,this);
        x+=5;
        if(x+50>d.width)
            x=0;
    }
}