Smokey effect : Stroke « 2D Graphics GUI « Java






Smokey effect

Smokey effect
      

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

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

public class Overlap extends JPanel {
  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.getContentPane().add(new Overlap());
    f.setSize(300, 200);
    f.setVisible(true);
  }

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    double x = 15, y = 50, w = 70, h = 70;
    Ellipse2D e = new Ellipse2D.Double(x, y, w, h);
    g2.setStroke(new BasicStroke(8));

    Color smokeyColor = new Color(128, 128, 128, 128);
    g2.setPaint(smokeyColor);
    g2.fill(e);
    g2.draw(e);

    e.setFrame(x + 100, y, w, h);
    g2.setPaint(Color.black);
    g2.draw(e);
    g2.setPaint(Color.gray);
    g2.fill(e);

    e.setFrame(x + 200, y, w, h);
    g2.setPaint(Color.gray);
    g2.fill(e);
    g2.setPaint(Color.black);
    g2.draw(e);
  }
}

           
         
    
    
    
    
    
  








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.Dashed strokeDashed stroke
7.Stroke with iron effectStroke with iron 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.