Stroking or Filling with a Texture - Java 2D Graphics

Java examples for 2D Graphics:Texture

Description

Stroking or Filling with a Texture

Demo Code


import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;

public class Main {
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    int x = 10;//from w  w w.  j a v  a2s  . com
    int y = 10;
    int width = 50;
    int height = 25;
    BufferedImage bufferedImage = null;
    TexturePaint texture = new TexturePaint(bufferedImage, new Rectangle(x, y,
        width, height));
    g2d.setPaint(texture);
    // Draw shapes...;
  }
}

Related Tutorials