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
验证下面的输出