forked from vizay08/Java_physics_library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhysicsApplet.java
92 lines (85 loc) · 1.56 KB
/
PhysicsApplet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.lang.Math;
import java.lang.Thread;
//<applet code="PhysicsApplet" width=750 height=750></applet>
public class PhysicsApplet extends Applet implements MouseListener,MouseMotionListener
{
private final double PI=22/7;
static Point pnew,pold;
int x,y;
int i;
int angle;
Acceleration acc;
Velocity vel;
boolean entered;
public void init()
{
angle=180;
acc=new Acceleration(0,0.1);
vel=new Velocity(1.0*Math.sin(angle*PI/180),-1.0*Math.cos(angle*PI/180));
pold=new Point();
pnew=new Point();
pold.x=100;
pold.y=300;
i=0;
entered=false;
x=10;
y=10;
addMouseListener(this);
addMouseMotionListener(this);
setBackground(Color.white);
setForeground(Color.gray);
}
public void mouseEntered(MouseEvent e)
{
entered=true;
//repaint();
}
public void mouseExited(MouseEvent e)
{
entered=false;
// repaint();
}
public void mouseClicked(MouseEvent e)
{
// repaint();
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
x=e.getX();
y=e.getY();
//repaint();
}
public void mouseDragged(MouseEvent e)
{
x=e.getX();
y=e.getY();
// repaint();
}
public void paint(Graphics g)
{
int j=0;
setForeground(Color.black);
try{
g.fillOval(pold.x,pold.y,100,100);
pnew=MyPhysicsLibrary.positionAfterTime(pold,acc,vel,i);
pold=pnew;
i++;
j++;
Thread.sleep(10);
repaint();
//g.drawString(pold.x+" "+pold.y,50,50);
}
catch(Exception e)
{
}
}
}