# Help with JOptionPane and triangles.

• 10-02-2013, 02:05 AM
Lach
Help with JOptionPane and triangles.
Hello!. I have to create a program that asks for a user to input 3 coordinates for a triangle, and then some calculations will be made such as perimeter and area, etc. So right now i have this:

Code:

```import java.util.Scanner; import javax.swing.JOptionPane; public class Triangle {   public static void main(String[] args) {   double side1 = 0;   double side2 = 0;   double side3 = 0;     //Coordinate 1   String side1x = JOptionPane.showInputDialog(null, "Enter x1 for point A: ", "User Input", JOptionPane.QUESTION_MESSAGE);     int x1 = Integer.parseInt(side1x);     String side1y = JOptionPane.showInputDialog(null, "Enter y1 for point A: ", "User Input", JOptionPane.QUESTION_MESSAGE);     int x2 = Integer.parseInt(side1y);     //Coordinate 2   String side2x = JOptionPane.showInputDialog(null, "Enter x2 for point B: ", "User Input", JOptionPane.QUESTION_MESSAGE);     int y1 = Integer.parseInt(side2x);     String side2y = JOptionPane.showInputDialog(null, "Enter y2 for point B: ", "User Input", JOptionPane.QUESTION_MESSAGE);     int y2 = Integer.parseInt(side2y);     //Coordinate 3   String side3x = JOptionPane.showInputDialog(null, "Enter x3 for point C: ", "User Input", JOptionPane.QUESTION_MESSAGE);```
As of right now all this does is ask for user input of x1 ,x2, y1, y2, etc., and keeps them in separate variables. What i am wondering how to do is make it so that x1 and x2 could be combined together to create a coordinate of a point of the triangle. Can anyone help me on this one? Thanks in advance!
• 10-02-2013, 04:19 AM
Junky
Re: Help with JOptionPane and triangles.
For starters you do not want to combine x1 and x2. You want x1 and y1, x2 and y2, x3 and y3. Have a look at the Point class.