
/*
 * @(#) Texture.java 1.1 99/10/11
 * Copyright (c) 1999 Lawrence Rodrigues
 */
package app;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

import java.net.*;
import java.util.*;
import java.beans.*;
import javax.swing.*;
import java.awt.print.*;
import java.awt.geom.*;
//import com.vistech.graphics.*;

public class DrawTexture extends JComponent {
   BufferedImage offScrIm;
   Graphics2D offScrGc;

   public DrawTexture() {
      this.setBackground(Color.black);
      offScrIm = new BufferedImage(100,100, BufferedImage.TYPE_INT_RGB);
      offScrGc = offScrIm.createGraphics();
      setSize(280, 300);
   }

   private void drawSimpleTexture1(){
      BufferedImage bi = new BufferedImage(10,10, BufferedImage.TYPE_INT_RGB);
      Graphics2D texGc = bi.createGraphics();
      texGc.setColor(Color.blue);
      texGc.fillOval(0,0,10,10);
      texGc.setColor(Color.red);
      texGc.fillRect(4,4,3,3);

      TexturePaint  texturePaint = new TexturePaint(bi, new Rectangle(0,0,10,10));

      offScrGc.setPaint(texturePaint);
      offScrGc.fillRect(0,0,100,100);
   }

   private void drawTexture2(){
      BufferedImage bi = new BufferedImage(10,10, BufferedImage.TYPE_INT_RGB);
      Graphics2D texGc = bi.createGraphics();
      texGc.setColor(Color.blue);
      texGc.fillOval(0,0,5,5);
      texGc.setColor(Color.red);
      texGc.fillOval(5,5,5,5);

      TexturePaint  texturePaint = new TexturePaint(bi, new Rectangle(0,0,10,10));

      offScrGc.setPaint(texturePaint);
      offScrGc.fillRect(0,0,100,100);
   }

   public void drawTexture3() {
      BufferedImage bi = new BufferedImage(10,10, BufferedImage.TYPE_INT_RGB);
      Graphics2D texGc = bi.createGraphics();
      texGc.setColor(Color.blue);
      texGc.fillOval(0,0,5,5);
      texGc.setColor(Color.green);
      texGc.fillOval(0,5,5,5);
      texGc.setColor(Color.yellow);
      texGc.fillOval(5,0,5,5);
      texGc.setColor(Color.red);
      texGc.fillOval(5,5,5,5);

      TexturePaint  texturePaint = new TexturePaint(bi, new Rectangle(0,0,10,10));

      offScrGc.setPaint(texturePaint);
      offScrGc.fillRect(0,0,100,100);

   }

 public void drawTexture4() {
      BufferedImage bi = new BufferedImage(10,10, BufferedImage.TYPE_INT_RGB);
      Graphics2D texGc = bi.createGraphics();
      texGc.setColor(Color.blue);
      texGc.fillOval(0,0,5,5);
      texGc.setColor(Color.green);
      texGc.fillRect(0,5,5,5);
      texGc.setColor(Color.yellow);
      texGc.fillRect(5,0,5,5);
      texGc.setColor(Color.red);
      texGc.fillRect(5,5,5,5);

      TexturePaint  texturePaint = new TexturePaint(bi, new Rectangle(0,0,10,10));

      offScrGc.setPaint(texturePaint);
      offScrGc.fillRect(0,0,100,100);

   }

   protected void paintComponent(Graphics g){
      Graphics2D g2d = (Graphics2D)g;
      int x =20; int y =20;
      drawSimpleTexture1();
      g2d.drawImage(offScrIm, x, y, this);
      drawTexture2();
      x = 140;
      g2d.drawImage(offScrIm, x, y, this);
      drawTexture3();
      y = 140;
      g2d.drawImage(offScrIm, x, y, this);
      drawTexture4();
      x = 20;
      g2d.drawImage(offScrIm, x, y, this);
   }

   public static void  main(String[] args){
      DrawTexture cv = new DrawTexture();
      JFrame fr = new JFrame();
      fr.addWindowListener(
            new WindowAdapter(){
               public void windowClosing(WindowEvent e){
                  System.exit(0);
               }
             }
      );
      fr.setTitle("Drawing Texture");
      fr.getContentPane().add(cv);
      fr.pack();
      fr.setSize(280,300);
      fr.show();
      cv.repaint();
    }
 }
