?? line.java
字號:
/*
* Line.java
*
* Created on 2007年4月23日, 下午11:57
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package paintbox;
/**
*
* @author fly
*/
import java.awt.*;
public class Line extends Shape{
/** Creates a new instance of Line */
private Point firstPoint;
private Point secondPoint;
public Line (Color color, Point p1, Point p2)
{
super();
strokeColor = color;
firstPoint = p1;
secondPoint = p2;
}
public void setEndPoint (Point endPoint)
{
secondPoint = endPoint;
}
public void draw (Graphics page)
{
page.setColor (strokeColor);
page.drawLine (firstPoint.x, firstPoint.y, secondPoint.x,
secondPoint.y);
if(slected)
{
page.setColor(Color.BLACK);
page.fillOval(firstPoint.x-3,firstPoint.y-3,6,6);
page.fillOval(secondPoint.x-3,secondPoint.y-3,6,6);
}
}
public void positionChanged(int xChanged, int yChanged)
{
firstPoint.x+=xChanged;
firstPoint.y+=yChanged;
secondPoint.x+=xChanged;
secondPoint.y+=yChanged;
}
public boolean isSlected(Point point)
{
boolean s=false;
s=(Math.abs(point.x-firstPoint.x)<10)&&(Math.abs(point.y-firstPoint.y)<10) ||
(Math.abs(point.x-secondPoint.x)<10)&&(Math.abs(point.y-secondPoint.y)<10);
return s;
}
public Object clone()
{
A a=new A();
return a.getLine();
}
private class A
{
public Line line;
public A()
{
Point point1=new Point(firstPoint.x, firstPoint.y);
Point point2=new Point(secondPoint.x, secondPoint.y);
line=new Line(strokeColor,point1,point2);
}
public Line getLine()
{
return line;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -