BasicStroke的类声明中的颜色默认sRGB颜色空间或颜色的任意颜色空间中的颜色确定。
类的声明
以下是声明的java.awt.BasicStroke类:
publicclassBasicStrokeextendsObjectimplementsStroke
字段域
以下是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.java
packagecom.yiibai.gui;importjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;publicclassAWTGraphicsDemoextendsFrame{publicAWTGraphicsDemo(){super("Java AWT Examples");prepareGUI();}publicstaticvoidmain(String[]args){AWTGraphicsDemoawtGraphicsDemo=newAWTGraphicsDemo();awtGraphicsDemo.setVisible(true);}privatevoidprepareGUI(){setSize(400,400);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventwindowEvent){System.exit(0);}});}@Overridepublicvoidpaint(Graphicsg){Graphics2Dg2=(Graphics2D)g;g2.setStroke(newBasicStroke(3.0f));g2.setPaint(Color.blue);Rectangle2Dshape=newRectangle2D.Float();shape.setFrame(100,150,200,100);g2.draw(shape);Rectangle2Dshape1=newRectangle2D.Float();shape1.setFrame(110,160,180,80);g2.setStroke(newBasicStroke(1.0f));g2.draw(shape1);FontplainFont=newFont("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
验证下面的输出
¥ 我要打赏
纠错/补充
收藏
下一篇:哥,这回真没有了
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。