COMP163 Global Direction Program Write a program with a Graphical User Interface
ID: 3750529 • Letter: C
Question
COMP163 Global Direction Program Write a program with a Graphical User Interface (GUI) that will display the direction from Greensboro to atan2( sin(longitude - gboroLongcoslatitude), cos(gboroLat) any point on the globe. The direction can be calculated by *sin( latitude)- sin gboroLat) * cos( latitude) *cos( longitude -gboroLong)) where: longitude latitude gboroLong is the longitude of the destination in radians is the latitude of the destination in radians is the longitude of Greensboro in radians ts the latitude of Greensboro in radians Positive latitudes are north of the equator, negative latitudes are south. Positive longitudes are east of the zero meridian and negative longitudes are to the west. Note that atan2 is a method of the Math class that takes two parameters separated by a comma. The program should input the latitude and longitude of the destination as degrees and minutes. You will have to convert to radians using the equation radians(etegrees 6180 minutes) 60 180 180 Convert the calculated direction in radians to degrees by degrees - radians Some interesting locations city latitude longitude deg, mindeg, min Greensboro San Francisco London Paris Mecca Perth Mumbai 36 4 -79-47 122-47 377 51 30 48 51 21 25" 2 21 39 48 31 -57115 51 19* 1 72° 51Explanation / Answer
Create a java file named AnAppletWithTextFields.java.
Copy paste following code:-
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class AnAppletWithTextFields extends Applet implements ActionListener {
public void init() {
Label label1 = new Label("Enter Latitude degrees & minutes");
tf1 = new TextField();
tf2 = new TextField();
Label label2 = new Label("Enter Longitude degrees & minutes");
tf3 = new TextField();
tf4 = new TextField();
b1 = new Button("OK");
b1.addActionListener(this);
result = new Label();
add(label1);
add(tf1);
add(tf2);
add(label2);
add(tf3);
add(tf4);
add(b1);
add(result);
}
public void actionPerformed(ActionEvent e) {
double la1=Double.parseDouble(tf1.getText());
double la2=Double.parseDouble(tf2.getText());
double lo1=Double.parseDouble(tf3.getText());
double lo2=Double.parseDouble(tf4.getText());
double gboroLat=(36.0+4.0/60.0)*(Math.PI/180.0);
double gboroLong=(-79.0-47.0/60.0)*(Math.PI/180.0);
double latti=(la1+la2/60.0)*(Math.PI/180.0);
double longi=(lo1+lo2/60.0)*(Math.PI/180.0);
double res=Math.atan2(Math.sin(longi-gboroLong)*Math.cos(latti), Math.cos(gboroLat)*Math.sin(latti)-Math.sin(gboroLat)*Math.cos(latti)*Math.cos(longi-gboroLong));
res=res*(double)(180.0/Math.PI);
String val=res+" degrees";
result.setText(val);
}
TextField tf1,tf2,tf3,tf4;
Button b1;
Label result;
}
Then compile the file and create another html file to run the applet (say applet.html).
copy paste following code:-
<applet code="AnAppletWithTextFields" width="600" height="50">
</applet>
Then, to run applet type following command in command prompt:-
AppletViewer applet.html
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.