目录

BasicStroke

介绍 (Introduction)

BasicStroke类声明默认sRGB颜色空间中的颜色或ColorSpace标识的任意颜色空间中的颜色。

类声明

以下是java.awt.BasicStroke类的声明:

public class BasicStroke
   extends Object
      implements Stroke

字段 (Field)

以下是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 - 通过在半径为线宽的半径处舍入角来连接路径段。

类构造函数

SN 构造函数和描述
1

BasicStroke()

使用所有属性的默认值构造一个新的BasicStroke。

2

BasicStroke(float width)

使用指定的线宽构造一个实心的BasicStroke,并使用cap和join样式的默认值。

3

BasicStroke(float width, int cap, int join)

构造具有指定属性的实体BasicStroke。

4

BasicStroke(float width, int cap, int join, float miterlimit)

构造具有指定属性的实体BasicStroke。

5

BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase)

构造具有指定属性的新BasicStroke。

类方法

SN 方法和描述
1

Shape createStrokedShape(Shape s)

返回一个Shape,其内部定义指定Shape的描边轮廓。

2

boolean equals(Object obj)

通过首先测试它是否是BasicStroke,然后将其宽度,连接,上限,斜接限制,破折号和破折号阶段属性与此BasicStroke的属性进行比较,测试指定对象是否等于此BasicStroke。

3

float[] getDashArray()

返回表示短划线段长度的数组。

4

float getDashPhase()

返回当前的破折号阶段。

5

int getEndCap()

返回端盖样式。

6

int getLineJoin()

返回行连接样式。

7

float getLineWidth()

返回行宽。

8

float getMiterLimit()

返回斜接连接的限制。

9

int hashCode()

返回此笔划的哈希码。

方法继承

该类继承以下类中的方法:

  • java.lang.Object

BasicStroke示例

使用您选择的任何编辑器创建以下java程序,例如D:/ 》 AWT 》 com 》 iowiki 》 gui 》

AWTGraphicsDemo.java
package com.iowiki.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("IoWiki", 130, 200);
   }
}

使用命令提示符编译程序。 转到D:/ 》 AWT并键入以下命令。

D:\AWT>javac com\iowiki\gui\AwtGraphicsDemo.java

如果没有错误,那意味着编译成功。 使用以下命令运行程序。

D:\AWT>java com.iowiki.gui.AwtGraphicsDemo

验证以下输出

AWT BasicStroke
↑回到顶部↑
WIKI教程 @2018