I need help with the if else statement below. I am trying to use branching to determine and drawString to find the longest lines between the points. Everything I try with the branching method seems to give me errors so I have no idea what to do and it is making my code look horrible. Any help is appreciated.
thank you
package program1;
import java.awt.Color;
import javax.swing.JFrame;
import java.awt.Graphics;
import javax.swing.JOptionPane;
public class Program1 extends JFrame {
private static final int FRAME_SIZE = 400;
private int x1,y1,x2,y2,x3,y3;
double Distance1;
double Distance2;
double Distance3;
public static void main(String[] args) {
Program1 guiWindow = new Program1 ();
guiWindow.setSize(FRAME_SIZE, FRAME_SIZE);
guiWindow.setDefaultCloseOperation(EXIT_ON_CLOSE);
String valueString;
valueString = JOptionPane.showInputDialog("Enter the X-coordinate for point A");
guiWindow.x1 = Integer.parseInt(valueString);
valueString = JOptionPane.showInputDialog("Enter the Y-coordinate for point A");
guiWindow.y1 = Integer.parseInt(valueString);
valueString = JOptionPane.showInputDialog("Enter the X-coordinate for point B");
guiWindow.x2 = Integer.parseInt(valueString);
valueString = JOptionPane.showInputDialog("Enter the Y-coordinate for point B");
guiWindow.y2 = Integer.parseInt(valueString);
valueString = JOptionPane.showInputDialog("Enter the X-coordinate for point C");
guiWindow.x3 = Integer.parseInt(valueString);
valueString = JOptionPane.showInputDialog("Enter the Y-coordinate for point C");
guiWindow.y3 = Integer.parseInt(valueString);
guiWindow.setVisible(true);
}
@Override
public void paint (Graphics g) {
super.paint(g);
Graphics canvas = getGraphics();
canvas.drawLine(x1, y1, x2, y2);
canvas.drawLine(x1, y1, x3, y3);
canvas.drawLine(x2, y2, x3, y3);
g.drawString("A", x1, y1);
g.drawString("B", x2, y2);
g.drawString("C", x3, y3);
Distance1 = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
Distance2 = Math.sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
Distance3 = Math.sqrt((x3-x1)*(x3-x1)+(y3-y2)*(y3-y2));
}
if (Distance1 > Distance2) && (Distance1 > Distance3)
{
drawString("Line AB is the longest");
}
else if (Distance2 > Distance3) && (Distance2 > Distance1)
{
drawString("Line BC is the longest");
}
else if (Distance3 > Distance2) && (Distance3 > Distance1)
{
drawString("Line AC is the longest");
}
else if (Distance1 == Distance2) && (Distance1 > Distance3)
{
drawString("Lines AB and BC are the longest");
}
else if (Distance2 == Distance3) && (Distance2 > Distance1)
{
drawString("Lines BC and AC are the longest");
}
else if (Distance1 == Distance3) && (Distance1 > Distance3)
{
drawString("Lines AB and AC are the longest");
}
}