ndfkldf2456982 于 2014.09.17 22:23 提问

java中找不到符号..就姜

import java.util.*;
import java.awt.geom.*;
import javax.swing.JOptionPane;
class Point
{
private double x,y;
Point(double x1,double y1)
{
x=x1;
y=y1;
}
Point()
{
this(0,0);
}
Point(Point p)
{
this(p.getX(),p.getY());
}
void setX(double x1)
{
x=x1;
}
void setY(double y1)
{
y=y1;
}
double getX()
{
return x;
}
double getY()
{
return y;
}
void moveTo(double x1,int y1)
{
x=x1;
y=y1;
}
}
public class MyLine{
private Point e1,e2;
MyLine()
{
e1=new Point(0.0,0.0);
e2=new Point(0.0,0.0);
}
MyLine(Point p1,Point p2)
{
e1=new Point(p1);
e1=new Point(p2);
}
MyLine(Point p1)
{
e1=new Point(0,0);
e2=new Point(p1);
}
void setE1(Point p)
{
e1=p;
}
void setE2(Point p)
{
e2=p;
}
Point getE1()
{
return e1;
}
Point getE2()
{
return e2;
}
boolean check()
{
if(e1.getX()>0&&e1.getY()>0&&e2.getX()>0&&e2.getY()>0) return true;
else return false;
}
double length()
{
double leng;
leng=Math.sqrt((e1.getX()-e2.getX())*(e1.getX()-e2.getX())+(e1.getY()-e2.getY())*(e1.getY()-e2.getY()));
return leng;
}
boolean intersect(MyLine line2)
{
boolean result;
result=Line2D.linesIntersect(getE1().getX(),getE1().getY(),getE2().getX(),getE2().getY(),line2.getE1().getX(),line2.getE1().getY(),line2.getE2().getX(),line2.getE2().getY());
return result;
}
double distance(Point p)
{
double result;
result=Line2D.ptLineDist(getE1().getX(),getE1().getY(),getE2().getX(),getE2().getY(),p.getX(),p.getY());
return result;
}
public static void main(String args[])
{
boolean result;
MyLine line1, line2;

``````String s="请在下面对话框中输入第一条直线的两点坐标";;
String s1=JOptionPane.showInputDialog("\n第一个点的横坐标x");
String s2=JOptionPane.showInputDialog("\n第一个点的纵坐标y");
String s3=JOptionPane.showInputDialog("\n第一个点的横坐标x");
String s4=JOptionPane.showInputDialog("\n第一个点的纵坐标y");
Point pone=new Point(Double.parseDouble(s1),Double.parseDouble(s2));
Point ptwo=new Point(Double.parseDouble(s3),Double.parseDouble(s4));
s="请在下面对话框中输入第二条直线的两点坐标";
s1=JOptionPane.showInputDialog("\n第一个点的横坐标x");
s2=JOptionPane.showInputDialog("\n第一个点的纵坐标y");
s3=JOptionPane.showInputDialog("\n第一个点的横坐标x");
s4=JOptionPane.showInputDialog("\n第一个点的纵坐标y");
Point pthree=new Point(Double.parseDouble(s1),Double.parseDouble(s2));
Point pfour=new Point(Double.parseDouble(s3),Double.parseDouble(s4));
s1=JOptionPane.showInputDialog("请在下面对话框中输入一个点的横坐标");
s2=JOptionPane.showInputDialog("请在下面对话框中输入一个点的纵坐标");
Point ptive=new Point(Double.parseDouble(s1),Double.parseDouble(s2));
line1=new MyLine(pone,ptwo);
line2=new MyLine(pthree,pfour);

result=line1.check();
System.out.print("线段(("+pone.getX()+","+pone.getY()+")("+ptwo.getX()+","+ptwo.getY()+"))");
if(result)System.out.println("在第一象限");
else System.out.println("在第一象限");

System.out.print("线段(("+pone.getX()+","+pone.getY()+")("+ptwo.getX()+","+ptwo.getY()+"))");
System.out.print("长度是 "+line1.length());
result=line1.intersect(line2);
System.out.print("线段(("+pone.getX()+","+pone.getY()+")("+ptwo.getX()+","+ptwo.getY()+"))");
System.out.print("与线段(("+pthree.getX()+","+pthree.getY()+")("+pfour.getX()+","+pfour.getY()+"))");
if(result) System.out.println("相交");
else System.out.println("不相交");

System.out.println("点("+pfive.getX()+","+pfive.getY()+")到线段(("+pone.getX()+","+pone.getY()+")("+ptwo    (这里)    .getX()+","+ptwo.(这里)        getY()+"))或其他延长线的距离是 "+line1(这里)   .distance(pfive));
``````

System.exit(0);
}
}