Thick stroke demo : Stroke « 2D Graphics GUI « Java






Thick stroke demo

Thick stroke demo
      

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 ThickStrokeDemo extends JPanel {
  public void init() {
    setBackground(Color.white);
  }

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(8.0f));
    g2.setPaint(Color.blue);
    
    Rectangle r = new Rectangle(5,5,200,200);
    
    g2.draw(r);
  }

  public static void main(String s[]) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    ThickStrokeDemo p = new ThickStrokeDemo();
    f.getContentPane().add("Center", p);
    p.init();
    f.pack();
    f.setSize(new Dimension(250, 250));
    f.show();
  }

}

           
         
    
    
    
    
    
  








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.Dashed strokeDashed stroke
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.