java basicstroke_AWT BasicStroke类

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

验证下面的输出

ef2169312a84991c84b0a201cec28b46.png

¥ 我要打赏

纠错/补充

收藏

下一篇:哥,这回真没有了

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值