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
選擇使用任何編輯器建立以下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
驗證下面的輸出