Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.text.*;
- public class PolarCoords extends JFrame
- {
- JFrame frameWin = new JFrame();
- frameWin.setBounds(100, 200, 120, 120);
- frameWin.setTitle("Polar Coordinates");
- frameWin.setVisible(true);
- frameWin.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- private JLabel rLabel;
- private JLabel thetaLabel;
- private JLabel r2Label;
- private JLabel theta2Label;
- private JLabel answerLabel;
- private static String rString = "R Coordinate";
- private static String thetaString = "Theta";
- private static String r2String = "R2 Coordinate";
- private static String theta2String = "Theta2";
- private static String answerString = "Answer";
- private JFormattedTextField rField;
- private JFormattedTextField thetaField;
- private JFormattedTextField r2Field;
- private JFormattedTextField theta2Field;
- private JFormattedTextField answerField;
- public PolarCoords(double rCoord, double theta)
- {
- return;
- }
- /**
- * Returns theta in (r, theta)
- * @param tTheta
- * @return
- */
- public double tTheta(double theta)
- {
- return theta;
- }
- /**
- * Returns r coordinate in (r, theta)
- * @param rCoord
- * @return
- */
- public double rRCoord(double rCoord)
- {
- return rCoord;
- }
- public Object magnitude()
- {
- double r1 = Double.valueOf(rField.getText());
- double theta1 = Double.valueOf(thetaField.getText());
- double r2 = 0;
- double theta2 = 0;
- double distance = Math.sqrt(Math.pow(r1, 2)) + Math.sqrt(Math.pow(r2, 2) - 2*(r1*r2) * Math.cos(theta1 - theta2));
- return distance;
- }
- public Double angleFromOrigin()
- {
- double theta1 = Double.valueOf(thetaField.getText());
- double theta2 = Double.valueOf(theta2Field.getText());
- double answer = theta2 - theta;
- return answer;
- }
- public Object distanceFromPoint()
- {
- // Distance formula Ã(r1)^2 + (r2)^2 - 2(r1)(r2) cos ( degree1 - degree2 )
- double r1 = Double.valueOf(rField.getText());
- double theta1 = Double.valueOf(thetaField.getText());
- double r2 = Double.valueOf(r2Field.getText());
- double theta2 = Double.valueOf(theta2Field.getText());
- double distance = Math.sqrt(Math.pow(r1, 2)) + Math.sqrt(Math.pow(r2, 2) - 2*(r1*r2) * Math.cos(theta1 - theta2));
- return distance;
- }
- public PolarCoords addPoints()
- {
- double r1 = Double.valueOf(rField.getText());
- double theta1 = Double.valueOf(thetaField.getText());
- double r2 = Double.valueOf(r2Field.getText());
- double theta2 = Double.valueOf(theta2Field.getText());
- double x = r1 * Math.cos(theta1);
- double y = r1 * Math.sin(theta1);
- double x2 = r2 * Math.cos(theta1);
- double y2 = r2 * Math.sin(theta2);
- double xAnswer = x2 - x;
- double yAnswer = y2 - y;
- double answer = Math.atan2(xAnswer, yAnswer);
- PolarCoords polarAnswer = new PolarCoords(xAnswer, yAnswer);
- return polarAnswer;
- }
- public static void main(String[] args)
- {
- Frame f = new Frame();
- System.out.print("Visible = True");
- }
- }
- //JFrame frameWin = new JFrame();
- frameWin.setBounds(100, 200, 120, 120);
- frameWin.setTitle("Polar Coordinates");
- frameWin.setVisible(true);
- frameWin.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
- setBounds(100, 200, 120, 120);
- setTitle("Polar Coordinates");
- setVisible(true);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
- public class PolarCoords extends JFrame
- {
- public PolarCoords()
- {
- setBounds(100, 200, 120, 120);
- setTitle("Polar Coordinates");
- setVisible(true);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
- }
- }
- public class PolarCoords extends JFrame
- {
- public PolarCoords()
- {
- Init();
- }
- public void Init()
- {
- setBounds(100, 200, 120, 120);
- setTitle("Polar Coordinates");
- setVisible(true);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
- }
- }
- public PolarCoords(double rCoord, double theta) //u'r not even using rCoord and theta
- {
- this.setBounds(100, 200, 120, 120);
- this.setTitle("Polar Coordinates");
- this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- this.setVisible(true);
- }
Add Comment
Please, Sign In to add comment