?? line.java
字號:
package test.paint;
import java.awt.*;
import java.awt.event.MouseEvent;
/**
* Line類,實現(xiàn)畫直線的功能
* 作者:王珍,鐘雯
* 初始時間:2007 5-17
* 最后一次修改時間:2007 6-17
*/
public class Line extends RectBoundedShape {
/**
*無參構(gòu)造函數(shù)
*/
public Line() {
super();
}
/**
*調(diào)用父類的函數(shù)
*/
public Line(Color c, Stroke s, int x, int y) {
super(c, s, x, y);
}
/**
*作者:鐘雯
* 初始時間:2007 5-17
* 最后一次修改時間:2007 6-17
*/
public Line(Color c, Stroke s, int x, int y, int a, int b)
{
super(c, s, x, y);
endX = a;
endY = b;
}
/**
*記錄鼠標(biāo)按下時的起始點和鼠標(biāo)松開的終止點
* tan(30) = 0.577;
* tan(60) = 1.155;
*/
public void processCursorEvent(MouseEvent e, int t) {
if (t != MyShape.CURSOR_DRAGGED)
return;
int x = e.getX();
int y = e.getY();
if (e.isShiftDown()) {
if (x - startX == 0) { //vertical
endX = startX;
endY = y;
} else {
float slope = Math.abs(((float) (y - startY)) / (x - startX));
if (slope < 0.577) { //horizontal
endX = x;
endY = startY;
} else if (slope < 1.155) { //deg45
regulateShape(x, y);
} else { //vertical
endX = startX;
endY = y;
}
}
} else {
endX = x;
endY = y;
}
}
/**
* 畫一條直線
*作者:王珍
* 初始時間:2007 5-17
* 最后一次修改時間:2007 6-17
*/
public void draw(Graphics2D g) {
g.setColor(color);
g.setStroke(stroke);
g.drawLine(startX, startY, endX, endY);
}
public Rectangle getBounds() {
// TODO Auto-generated method stub
return null;
}
public boolean isImage() {
// TODO Auto-generated method stub
return false;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -