SHARE
TWEET

Untitled

a guest Jan 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.text.*;
  5.  
  6.  
  7. public class PolarCoords extends JFrame
  8. {
  9.  
  10.     JFrame frameWin = new JFrame();
  11.     frameWin.setBounds(100, 200, 120, 120);
  12.     frameWin.setTitle("Polar Coordinates");
  13.     frameWin.setVisible(true);
  14.     frameWin.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  15.  
  16.     private JLabel rLabel;
  17.     private JLabel thetaLabel;
  18.     private JLabel r2Label;
  19.     private JLabel theta2Label;
  20.     private JLabel answerLabel;
  21.  
  22.     private static String rString = "R Coordinate";
  23.     private static String thetaString = "Theta";
  24.     private static String r2String = "R2 Coordinate";
  25.     private static String theta2String = "Theta2";
  26.     private static String answerString = "Answer";
  27.  
  28.     private JFormattedTextField rField;
  29.     private JFormattedTextField thetaField;
  30.     private JFormattedTextField r2Field;
  31.     private JFormattedTextField theta2Field;
  32.     private JFormattedTextField answerField;
  33.  
  34.     public PolarCoords(double rCoord, double theta)
  35.     {
  36.         return;
  37.     }
  38.  
  39.     /**
  40.      * Returns theta in (r, theta)
  41.      * @param tTheta
  42.      * @return
  43.      */
  44.     public double tTheta(double theta)
  45.     {
  46.         return theta;
  47.     }
  48.  
  49.     /**
  50.      * Returns r coordinate in (r, theta)
  51.      * @param rCoord
  52.      * @return
  53.      */
  54.     public double rRCoord(double rCoord)
  55.     {
  56.         return rCoord;
  57.     }
  58.  
  59.     public Object magnitude()
  60.     {  
  61.         double r1 = Double.valueOf(rField.getText());
  62.         double theta1 = Double.valueOf(thetaField.getText());
  63.         double r2 = 0;
  64.         double theta2 = 0;
  65.         double distance = Math.sqrt(Math.pow(r1, 2)) + Math.sqrt(Math.pow(r2, 2) - 2*(r1*r2) * Math.cos(theta1 - theta2));
  66.         return distance;
  67.     }
  68.  
  69.     public Double angleFromOrigin()
  70.     {
  71.         double theta1 = Double.valueOf(thetaField.getText());
  72.         double theta2 = Double.valueOf(theta2Field.getText());
  73.         double answer = theta2 - theta;
  74.         return answer;
  75.     }
  76.  
  77.     public Object distanceFromPoint()
  78.     {
  79.         // Distance formula Ã(r1)^2 + (r2)^2 - 2(r1)(r2) cos ( degree1 - degree2 )
  80.         double r1 = Double.valueOf(rField.getText());
  81.         double theta1 = Double.valueOf(thetaField.getText());
  82.         double r2 = Double.valueOf(r2Field.getText());
  83.         double theta2 = Double.valueOf(theta2Field.getText());
  84.         double distance = Math.sqrt(Math.pow(r1, 2)) + Math.sqrt(Math.pow(r2, 2) - 2*(r1*r2) * Math.cos(theta1 - theta2));
  85.         return distance;
  86.     }
  87.  
  88.     public PolarCoords addPoints()
  89.     {
  90.         double r1 = Double.valueOf(rField.getText());
  91.         double theta1 = Double.valueOf(thetaField.getText());
  92.         double r2 = Double.valueOf(r2Field.getText());
  93.         double theta2 = Double.valueOf(theta2Field.getText());
  94.         double x = r1 * Math.cos(theta1);
  95.         double y = r1 * Math.sin(theta1);
  96.         double x2 = r2 * Math.cos(theta1);
  97.         double y2 = r2 * Math.sin(theta2);
  98.  
  99.         double xAnswer = x2 - x;
  100.         double yAnswer = y2 - y;
  101.         double answer = Math.atan2(xAnswer, yAnswer);
  102.         PolarCoords polarAnswer = new PolarCoords(xAnswer, yAnswer);
  103.         return polarAnswer;
  104.     }
  105.  
  106.     public static void main(String[] args)
  107.     {
  108.         Frame f = new Frame();
  109.         System.out.print("Visible = True");
  110.     }
  111.  
  112.  
  113. }
  114.    
  115. //JFrame frameWin = new JFrame();
  116.     frameWin.setBounds(100, 200, 120, 120);
  117.     frameWin.setTitle("Polar Coordinates");
  118.     frameWin.setVisible(true);
  119.     frameWin.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
  120.    
  121. setBounds(100, 200, 120, 120);
  122.  setTitle("Polar Coordinates");
  123.  setVisible(true);
  124.  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
  125.    
  126. public class PolarCoords extends JFrame
  127. {
  128.    public PolarCoords()
  129.    {
  130.      setBounds(100, 200, 120, 120);
  131.      setTitle("Polar Coordinates");
  132.      setVisible(true);
  133.      setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
  134.    }
  135. }
  136.    
  137. public class PolarCoords extends JFrame
  138. {
  139.    public PolarCoords()
  140.    {
  141.      Init();
  142.    }
  143.    public void Init()
  144.    {
  145.      setBounds(100, 200, 120, 120);
  146.      setTitle("Polar Coordinates");
  147.      setVisible(true);
  148.      setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) ;
  149.    }
  150. }
  151.    
  152. public PolarCoords(double rCoord, double theta) //u'r not even using rCoord and theta
  153. {
  154.     this.setBounds(100, 200, 120, 120);
  155.     this.setTitle("Polar Coordinates");
  156.     this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  157.     this.setVisible(true);
  158. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top