Basic stroke : Stroke « 2D Graphics GUI « Java

Basic stroke

Basic 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 BasicStrokeDemo extends JPanel {
  public void init() {

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3.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) {
    BasicStrokeDemo p = new BasicStrokeDemo();
    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.Thick stroke demoThick stroke demo
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.