Show Textured Paint

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture.

Show Textured Paint

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture.

Show Textured Paint

Show Textured Paint

     

This section shows you the textured paint.

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture. We are providing you an example that will show the textured paint.

The class TexturePaint provides an easy and impressive way to fill a shape with a repeating pattern. When you create a TexturePaint, you specify a BufferedImage to use as the pattern. The method createGraphics() creates a Graphics2D to draw into this BufferedImage.

To draw the oval we have used Ellipse2D class. To draw rectangle inside the oval, class Rectangle2D is used. The method g2d.fill(oval) fills the shape specified.

Here is the code of ShowTexturePaint.java

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;

public class ShowTexturePaint extends JPanel {
 
  public void paint(Graphics g) {
  Graphics2D g2d = (Graphics2D) g;
  BufferedImage bufferedImage = new BufferedImage(88,
  BufferedImage.TYPE_INT_RGB);
  Graphics2D g2 = bufferedImage.createGraphics();
  g2.setColor(Color.red);
  g2.fillRect(0088);
  g2.setColor(Color.gray);
  g2.fillOval(0088);
  Rectangle2D rect = new Rectangle2D.Double(5588);
  g2d.setPaint(new TexturePaint(bufferedImage, rect));
  Ellipse2D oval = new  Ellipse2D.Double(8,8,250,250);
  g2d.fill(oval);
  }
  public static void main(String args[]) {
  JFrame frame = new JFrame("Show Texture Paint");
  ShowTexturePaint texturePaint = new ShowTexturePaint();
  frame.getContentPane().add("Center", texturePaint);
  frame.setSize(350300);
  frame.setVisible(true);
  }
}

Output will be displayed as:

Download Source Code