Dashed stroke : Stroke « 2D Graphics GUI « Java

Dashed stroke

Dashed stroke

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class DashedStrokeDemo extends JPanel {
  public void init() {

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    float dash[] = { 10.0f };
    g2.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));

    Rectangle r = new Rectangle(5,5,200,200);

  public static void main(String s[]) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
    DashedStrokeDemo p = new DashedStrokeDemo();
    f.getContentPane().add("Center", p);
    f.setSize(new Dimension(250, 250));



Related examples in the same category

1.Dashed rectangleDashed rectangle
2.A dashed stroke
3.Stroking or Filling with a Texture
4.Basic strokeBasic stroke
5.Thick stroke demoThick stroke demo
6.Stroke with iron effectStroke with iron effect
7.Smokey effectSmokey effect
8.Custom StrokesCustom Strokes
9.Changing the Thickness of the Stroking Pen
10.Tries to deduct the stroke-type from the given stroke object.
11.Tries to extract the stroke-width from the given stroke object.
12.A component for choosing a stroke from a list of available strokes.
13.Cancel the effects of the zoom on a particular Stroke
14.Serialises a Stroke object
15.This program demonstrates different stroke types.This program demonstrates different stroke types.