Showing posts with label cannon bal using appletl in java. Show all posts
Showing posts with label cannon bal using appletl in java. Show all posts

Tuesday, March 11, 2014

cannon bal using appletl in java



import java.applet.Applet;
import java.awt.*;
import java.awt.color.*;
import javax.swing.*;
import javax.swing.event.*;

public class projectile extends Applet implements Runnable{

double x=0,y=0,u=110,t=0,m=40;
Thread th;
/* public void update (Graphics g)
{
paint(g);
}*/
public void paint(Graphics g)
{
setBackground(Color.yellow);
g.setColor(Color.BLUE);
g.fillOval((int)x, (int)y, 50, 50);
g.fillRect(0,500,1300,10);
}
public void init(){
setSize(1500,600);
}
public void start()
{
th=new Thread(this);
th.start();
}
public void run() {
double T=0;
while(t<=T)
{
m= Math.toRadians(m);
T=2*u*(Math.sin(m))/9.8;
x=100+u*(Math.cos(m))*t;
if(t<T/2)
y=500-(u*t*(Math.sin(m))-(0.5)*9.8*t*t);
else if(t>T/2)
y=500-(u*t*(Math.sin(m))-(0.5)*9.8*t*t);
else
y=y;
repaint();
m=Math.toDegrees(m);t=t+0.01;
try
{
Thread.sleep(4);
}
catch(InterruptedException ex)
{
}


}
}
}

Contributors

Translate