import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class MyGraphic extends java.applet.Applet implements ActionListener
{
boolean go =false;
int x, oldx, y, oldy;
double angle;
Button drawButton =new Button("Draw");
public void init()
{
add(drawButton);
drawButton.addActionListener(this);
}
public void paint(Graphics screen)
{
resize(500,500);
int x,y, oldx, oldy;
double i=0;
double a=0;
double b=0;
oldx=250;
oldy=250;
double ang=0;
double angle;
x=1;
if (go==true)
{
for (i=0; i<800; i=i+1)
{
a=a+.5;
b=b+.5;
ang=ang+.8;
x=(int)(a*Math.cos(ang)+250);
y=(int)(b*Math.sin(ang)+250);
screen.drawLine(x,y, oldx, oldy);
oldx=x;
oldy=y;
pause(1);
}
}
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source.equals(drawButton))
{
System.out.println("Started...");
go=true;
repaint();
}
}
void pause(int time)
{
try {
Thread.sleep(time);
}
catch (InterruptedException e) { }
}
}
/*<applet code="MyGraphic.java" height="500" width="300">
</applet>*/
OutPut:
mast program hai ........
ReplyDelete