AWT BasicStroke類
BasicStroke的類聲明中的顏色默認sRGB顏色空間或顏色的任意顏色空間中的顏色確定。
類的聲明
以下是聲明的java.awt.BasicStroke類:
public class BasicStroke extends Object implements Stroke
字段域
以下是java.awt.geom.Arc2D類字段:
-
static int CAP_BUTT -- 結束未封閉的子路徑和虛線線段與不加裝飾。
-
static int CAP_ROUND -- 結束未封閉的子路徑和虛線線段與一個圓形的裝飾,有一個半徑等於一半的筆寬。
-
static int CAP_SQUARE -- 結束未封閉的子路徑和虛線段的具有方形的突起,伸出的端部的線寬度的一半的距離等於的段。
-
static int JOIN_BEVEL -- 加入通過其廣泛的輪廓用直線段連接外眼角的路徑段。
-
static int JOIN_MITER -- 加入路徑段延伸的外邊緣,直到他們滿足。
-
static int JOIN_ROUND -- 加入路徑段,通過舍入的拐角處的半徑處的線寬度的一半。
類的構造函數
S.N. | 構造函數與說明 |
---|---|
1 |
BasicStroke() Constructs a new BasicStroke with defaults for all attributes. |
2 |
BasicStroke(float width) Constructs a solid BasicStroke with the specified line width and with default values for the cap and join styles. |
3 |
BasicStroke(float width, int cap, int join) Constructs a solid BasicStroke with the specified attributes. |
4 |
BasicStroke(float width, int cap, int join, float miterlimit) Constructs a solid BasicStroke with the specified attributes. |
5 |
BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) Constructs a new BasicStroke with the specified attributes. |
類方法
S.N. | 方法和說明 |
---|---|
1 |
Shape createStrokedShape(Shape s) Returns a Shape whose interior defines the stroked outline of a specified Shape. |
2 |
boolean equals(Object obj) Tests if a specified object is equal to this BasicStroke by first testing if it is a BasicStroke and then comparing its width, join, cap, miter limit, dash, and dash phase attributes with those of this BasicStroke. |
3 |
float[] getDashArray() Returns the array representing the lengths of the dash segments. |
4 |
float getDashPhase() Returns the current dash phase. |
5 |
int getEndCap() Returns the end cap style. |
6 |
int getLineJoin() Returns the line join style. |
7 |
float getLineWidth() Returns the line width. |
8 |
float getMiterLimit() Returns the limit of miter joins. |
9 |
int hashCode() Returns the hashcode for this stroke. |
繼承的方法
這個類繼承的方法從以下類:
-
java.lang.Object
BasicStroke 實例
選擇使用任何編輯器創建以下java程序 D:/ > AWT > com > yiibai > gui >
AWTGraphicsDemo.javapackage com.yiibai.gui; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class AWTGraphicsDemo extends Frame { public AWTGraphicsDemo(){ super("Java AWT Examples"); prepareGUI(); } public static void main(String[] args){ AWTGraphicsDemo awtGraphicsDemo = new AWTGraphicsDemo(); awtGraphicsDemo.setVisible(true); } private void prepareGUI(){ setSize(400,400); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); } @Override public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setStroke(new BasicStroke(3.0f)); g2.setPaint(Color.blue); Rectangle2D shape = new Rectangle2D.Float(); shape.setFrame(100, 150, 200,100); g2.draw(shape); Rectangle2D shape1 = new Rectangle2D.Float(); shape1.setFrame(110, 160, 180,80); g2.setStroke(new BasicStroke(1.0f)); g2.draw(shape1); Font plainFont = new Font("Serif", Font.PLAIN, 24); g2.setFont(plainFont); g2.setColor(Color.DARK_GRAY); g2.drawString("TutorialsPoint", 130, 200); } }
編譯程序,使用命令提示符。進入到D:/> AWT,然後鍵入以下命令。
D:AWT>javac comyiibaiguiAwtGraphicsDemo.java
如果冇有錯誤出現,這意味著編譯成功。使用下麵的命令來運行程序。
D:AWT>java com.yiibai.gui.AwtGraphicsDemo
驗證下麵的輸出