002
11.06.2004, 17:06 Uhr
kaihua
|
Code: |
//------------ Class Line ------------ class Line extends ProgrammZustand { public Line() { super(); zustand = LINE; } public Line(int sx, int sy, int ex, int ey) { super(sx, sy, ex, ey); zustand = LINE; } public boolean isContain(int x, int y) { double c = Math.sqrt((endX-startX)*(endX-startX)+(endY-startY)*(endY-startY)); double c1 = Math.sqrt((x-startX)*(x-startX)+(y-startY)*(y-startY)); double c2 = Math.sqrt((endX-x)*(endX-x)+(endY-y)*(endY-y));
if(c1+c2-c <= 2) { isSelected = true; return true; } else { isSelected = false; return false; } } } //------------ Class Rectangle ------------ class Rectangle extends ProgrammZustand { public Rectangle() { super(); zustand = RECTANGLE; } public Rectangle(int sx, int sy, int ex, int ey) { super(sx, sy, ex, ey); zustand = RECTANGLE; } public boolean isContain(int x, int y) { if(x >= minX() && x <= maxX() && y >= minY() && y <= maxY()) { isSelected = true; return true; } else { isSelected = false; return false; } } } //------------ Class Ellipse ------------ class Ellipse extends ProgrammZustand { private double dx; // MittelPunkt private double dy; private double a; // L鋘ge a private double b; // L鋘ge b public Ellipse() { super(); zustand = ELLIPSE; } public Ellipse(int sx, int sy, int ex, int ey) { super(sx, sy, ex, ey); zustand = ELLIPSE; } public boolean isContain(int x, int y) { dx = (double) (startX+endX) / 2; dy = (double) (startY+endY) / 2; a = (double) (maxX()-minX()) / 2; b = (double) (maxY()-minY()) / 2;
double x1 = (x-dx)*(x-dx) / (a*a); double y1 = (y-dy)*(y-dy) / (b*b); if(x1+y1 <= 1) { isSelected = true; return true; } else { isSelected = false; return false; }
} } //------------ Class Circle ------------ class Circle extends ProgrammZustand { private double dx; // MittelPunkt private double dy; private double r; // Radius
public Circle() { super(); zustand = CIRCLE; } public Circle(int sx, int sy, int ex, int ey) { super(sx, sy, ex, ey); zustand = CIRCLE; } public boolean isContain(int x, int y) { dx = (double) (startX+endX) / 2; dy = (double) (startY+endY) / 2; r = 0.5*Math.sqrt(Math.pow((endX-startX), 2));
if((x-dx)*(x-dx)+(y-dy)*(y-dy)<=r*r) //und temp.stored = false { isSelected = true; return true; } else { isSelected = false; return false; }
} } //------------ Class Text ------------ class Text extends ProgrammZustand { static String myText = " "; public Text() { super(); super.text = new String(); zustand = TEXT; } public Text(int sx, int sy, String theText) { super.startX = sx; super.startY = sy; super.isSelected = false; super.isFill = false; super.color = Color.BLACK; myText = theText; zustand = TEXT; } public void setText(String theText) { // super.startX = sx; // super.startY = sy; super.isSelected = false; super.isFill = false; super.color = Color.BLACK; myText = theText; zustand = TEXT; } } //------------ Class Raster ------------ class Raster extends ProgrammZustand { static final int ABSTAND = 20; public Raster() { super(); zustand = RASTER; } }
|
// continued |