/*
1. Create a Frame inside an applet and rotate a shape inside the frame using java2D (Graphics2D
class)
Run similer to frames
javac Program1.java
java Program
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.concurrent.TimeUnit;
public class Program1 extends java.applet.Applet
{
private int width = 500;
private int height = 500;
private int x = width / 2;
private int y = height / 2;
private double direction=1;
private double angle=5;
private double vX;
private double vY;
int a =100, b=100;
public void init()
{
}
public void paint(Graphics g)
{
// g.drawRect(50, 35, 150, 150);
g.setColor( Color.BLACK );
g.fillRect( 0, 0, width, height );
g.setColor( Color.WHITE );
g.drawString(" The angle of Rotation: " + angle, 10, 10 );
try{
for (int i = 0; i<360; i++){
TimeUnit.SECONDS.sleep(1);
// angle=10;
direction = Math.PI / 360;
//vX = Math.cos( angle )*angle ;
vX= a *Math. cos( i) ;
//vY = Math.sin( angle ) *angle ;
vY = b * Math.sin( i) ;
g.clearRect(1, 1, width - 2, height - 2);
g.setColor( Color.BLACK );
g.fillRect( 0, 0, width, height );
g.setColor( Color.WHITE );
g.drawString(" The angle of Rotation: " + angle+ " "+vX +" "+vY , 10, 10 );
// g.drawOval(x ,y ,a,b);
g.drawOval(x +(int)vX, y +(int)vY , 60, 100);
}
} catch(InterruptedException e) {}
}
static Frame f;
public static void main(String [] args)
{
f = new Frame("Applet c");
Applet ex = new Applet();
f .add(new Program1());
//f.add("Center", ex);
f.pack();
f.show();
f.setSize(500,500);
}
}