-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentV1.java
More file actions
56 lines (44 loc) · 1.4 KB
/
Copy pathEnvironmentV1.java
File metadata and controls
56 lines (44 loc) · 1.4 KB
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
import acm.program.*;
import java.awt.event.*;
import java.lang.Exception;
import javax.swing.*;
/*
* This class serves as the graphical environment for the simulation.
*/
public class EnvironmentV1 extends GraphicsProgram{
private Drone drone;
public static final int APPLICATION_WIDTH=1400, APPLICATION_HEIGHT=1000;
private Calculator calc;
public void init(){
double startX = 200, startY = 600;
JFrame frame = new JFrame("Drone Readout");
frame.setVisible(true);
frame.setSize(300,200);
JTextArea readout = new JTextArea();
frame.add(readout);
readout.setEditable(false);
drone = new Drone(startX,startY,0.1,this);
try{
calc = new Calculator(startX,startY,0.033333,drone,readout,this);
}
catch(Exception e){
new PopUpBox("Could not connect to a\ncontroller... exiting!","Connection Error!");
System.exit(1);
}
(new Thread(calc)).start();
(new Thread(drone)).start();
addKeyListeners();
addMouseListeners();
try{
//We wait just to ensure the controller is properly mounted before beginning, if there is an error it will become
//apparent before the computer awakens, hopefully....
Thread.sleep(100);
}
catch(java.lang.InterruptedException e){
}
calc.startFlight();
}
public void mousePressed(MouseEvent e){
calc.reset(e.getX(),e.getY());
}
}