?? circle.java
字號:
package Painter;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import main.MyCanvas;
/**
* 畫圓
*/
public class Circle extends Shape {
// 圓心位置,x、y坐標(biāo)
private int x;
private int y;
// 圓的半徑
private int radius;
private boolean fill= false; //是否實(shí)心
// 構(gòu)造方法
public Circle(Color ColorPen,Color ColorBrush,int LineWide,
int x, int y, int radius, boolean Fill) {
super(ColorPen,ColorBrush,LineWide);
this.x = x;
this.y = y;
this.radius = radius;
fill = Fill;
}
// 判斷圓是否被選中
public boolean IsPoint(int x,int y,float j1)
{
float xx;
xx = DisPoint(x,y,this.x,this.y);
if(!fill)
{
if(xx > this.radius - j1 && xx < this.radius + j1)
return true;
}
else
{
if(xx <= this.radius)
return true;
}
return false;
}
// 判斷是圓還是區(qū)域
boolean IsCircle()
{
return !fill;
}
// 畫圓
public void draw(Graphics g,int m_DrawMode,Color bgColor) {
Graphics2D g2d = (Graphics2D) g;
// 設(shè)置畫筆顏色
// if(b_Delete==true)
// return;
g2d.setColor(super.m_ColorPen);
g2d.setStroke(MyCanvas.STROKES[super.m_LineWide]);
// drawArc畫弧,當(dāng)弧的寬度和高度一樣,而且弧度從0到360度時(shí),便是圓了。
if(m_DrawMode == 0) //正常畫圖)
{
if(fill == false){
g.drawArc(this.x, this.y, this.radius, this.radius, 0, 360);
}
else{
System.out.println("Draw Circle: " + fill);
g2d.drawArc(this.x, this.y, this.radius, this.radius, 0, 360);
g2d.setColor(super.m_ColorBrush);
g2d.fillArc(this.x, this.y, this.radius, this.radius, 0, 360);
}
}
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.setStroke(thindashed);
g2d.setColor(Color.RED);
if(fill == false){
g2d.drawArc(this.x, this.y, this.radius, this.radius, 0, 360);
}
else{
g2d.drawArc(this.x, this.y, this.radius, this.radius, 0, 360);
g2d.setColor(Color.RED);
g2d.fillArc(this.x, this.y, this.radius, this.radius, 0, 360);
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -