?? cusstring.java
字號:
package Painter;/* 軟件作者: 熊錫君,時守剛 軟件版權(quán)歸作者所有,其他人可以對軟件進行修改,可以使用軟件代碼,(按類使用請保留作者信息)*/import java.io.Serializable;import java.awt.*;import java.awt.geom.*;import java.awt.datatransfer.*;/** * CusString類,實現(xiàn)Serializable,CusShape接口 */public class CusString extends Shape{ public String aString; public int x,y; private Font aFont=new Font("",Font.BOLD,10); private Color col=Color.black; /** * 構(gòu)造函數(shù) * @param aString String * @param x int * @param y int */ public CusString (String aString,int x,int y) { super(); this.aString=aString; this.x=x; this.y=y; } /** * 構(gòu)造函數(shù) * @param aString String * @param x int * @param y int * @param aFont Font * @param col Color */ public CusString(String aString,int x,int y,Font aFont,Color col) { this.aString=aString; this.x=x; this.y=y; this.aFont=aFont; this.col=col; } /** * 設置字體 * @param f Font */ public void setFont(Font f) { this.aFont=f; } /** * 得到字體 * @return Font */ public Font getFont() { return aFont; } /** * 判斷是否與x,y,w,h構(gòu)成的矩形相交 * @param x double * @param y double * @param w double * @param h double * @return boolean */ public boolean intersects(double x,double y,double w,double h) { Rectangle2D rec2D=new Rectangle2D.Float(this.x,this.y,aFont.getSize()*aString.length()/2,aFont.getSize()); return rec2D.intersects(x,y,w,h); } /** * 得到邊界 * @return Rectangle */ public java.awt.Rectangle getBounds() { return new java.awt.Rectangle(this.x,this.y,aFont.getSize()*aString.length()/2,aFont.getSize()); } /** * 設置位置 * @param x int * @param y int */ public void setLocation(int x,int y) { this.x=x; this.y=y; } /** * 設置顏色 * @param col Color */ public void setColor(Color col) { this.col=col; } public boolean IsPoint(int x,int y,float j1) { java.awt.Rectangle rect = this.getBounds(); int x1 = 0,y1 = 0,x2 = 0,y2 = 0; x1 = this.x; y1 = this.y; x2 = x1 + rect.width; y2 = y1 + rect.height; if((x >= x1-j1 && x <= x2+j1 && y >= y1-j1 && y <= y2+j1)) return true; return false; } /** * 得到顏色 * @return Color */ public Color getColor() { return col; } /** * 繪制方法 * @param g Graphics */ public void draw(Graphics g,int m_DrawMode,Color bgColor) { Graphics2D g2d=(Graphics2D)g;// if(super.b_Delete==true) // return; g2d.setColor(col); g2d.setFont(aFont); g2d.drawString(aString,x,y+aFont.getSize()); if(m_DrawMode != 0) { 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); java.awt.Rectangle rect = this.getBounds(); g2d.drawRect(this.x,this.y,rect.width,rect.height); } } /** * 設置是否填充,無意義 * @param isFill boolean */ public void setIsFill(boolean isFill) { } /** * 得到是否填充,無意義 * @return boolean */ public boolean getIsFill() { return false; } /** * 設置字體 * @param aStroke BasicStroke */ public void setStroke(BasicStroke aStroke) { } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -