?? line.java
字號:
package Painter;
/*
軟件作者: 熊錫君,時(shí)守剛
軟件版權(quán)歸作者所有,其他人可以對軟件進(jìn)行修改,可以使用軟件代碼,(按類使用請保留作者信息)
*/
import java.awt.Color;
import java.lang.Math;
import java.awt.Graphics;
import java.awt.*;
import main.MyCanvas;
/**
* 畫線
*/
public class Line extends Shape {
// 線的起點(diǎn)位置,x、y坐標(biāo)
private int x1;
private int y1;
// 線的終點(diǎn)位置,x、y坐標(biāo)
private int x2;
private int y2;
public Line(){
super(Color.BLACK,Color.BLACK,1);
}
//private ;
// 構(gòu)造方法
public Line(Color ColorPen,Color ColorBrush,int LineWide,
int x1, int y1, int x2, int y2) {
super(ColorPen,ColorBrush,LineWide);
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
// 得到直線的矩形邊界
public void GetRect(Point point1,Point point2)
{
point1.x = Math.min(x1,x2);
point2.x = Math.max(x1,x2);
point1.y = Math.min(y1,y2);
point2.y = Math.max(y1,y2);
}
// 判斷是否被點(diǎn)選中的函數(shù)
public boolean IsPoint(int x,int y,float j1)
{
float xx,x1=0,x2=0,y1=0,y2=0;
Point point1 = new Point();
Point point2 = new Point();
GetRect(point1,point2);
x1 = point1.x;
y1 = point1.y;
x2 = point2.x;
y2 = point2.y;
if(!(x >= x1-j1 && x <= x2+j1 && y >= y1-j1 && y <= y2+j1))
return false;
xx = super.PointLine(x,y,this.x1,this.y1,this.x2,this.y2);
if(xx < j1)
return true;
return false;
}
// 畫直線
public void draw(Graphics g,int m_DrawMode,Color bgColor) {
Graphics2D g2d = (Graphics2D) g;
// 設(shè)置畫筆顏色
g2d.setColor(super.m_ColorPen);
g2d.setStroke(MyCanvas.STROKES[super.m_LineWide]);
// drawLine方法畫線
if(m_DrawMode == 0) //正常畫圖
{
g2d.drawLine(this.x1,this.y1,this.x2,this.y2);
}
else{ //選中時(shí)特殊顯示
Stroke thindashed = new BasicStroke(2.0f,
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL,1.0f,
new float[]{8.0f,3.0f,2.0f,3.0f},
0.0f);
g2d.setColor(bgColor);
g2d.drawLine(this.x1,this.y1,this.x2,this.y2);
g2d.setStroke(thindashed);
g2d.setColor(super.m_ColorPen);
g2d.drawLine(this.x1,this.y1,this.x2,this.y2);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -