I have an application that does things with polar coordinates that is programmed in Java. I have to create a GUI for it and I decided to try to use swing components instead of this JAR called BreezyGUI. The issue I have is that I am unable to set the frame options without getting an error. How do I begin to design the interface after creating the frame, labels, and text fields? Any suggestions would really help me out, thanks!
The error I receive in Eclipse is not specific. It just has it highlighted red like it is a straight up miss type.
Here is my application:
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");
}
}