Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Text Texture Example 
 

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

 

Text Texture Example

                         

This section illustrates you how to show the textured text.

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture. A texture is a bitmap image applied to the surface in computer graphics. We can also fill our graphics shapes with textures.

We are providing you an example that will show the textured text. The BufferedImage data is copied by the TexturePaint object. The method getTextureImage() get the texture image. The class TexturePaint provides an impressive way to fill a shape with a repeating pattern. The Font class defines the font. The method bufferedImage.createGraphics() draw the graphics into the BufferedImage. Using setPaint() method, different colors are defined to show the texture..

Here is the code of TextTexturedExample.java

import java.awt.*;
import javax.swing.*;
import java.awt.image.*;

public class TextTexturedExample extends JPanel {
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Font font = new Font("Monotype Corsiva", Font.PLAIN, 40);
    g2d.setFont(font);
    String st = "Java is an Object Oriented Programming Language.";
    BufferedImage bufferedImage = getTextureImage();
    Rectangle rect = new Rectangle(00, bufferedImage.getWidth(),
            bufferedImage.getHeight());

    TexturePaint texturePaint = new TexturePaint(bufferedImage, rect);
    g2d.setPaint(texturePaint);
    g2d.drawString(st, 20100);
  }
  private BufferedImage getTextureImage() {
    int s=10;
    BufferedImage bufferedImage = new BufferedImage(s, s,
             BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bufferedImage.createGraphics();
    g2d.setPaint(Color.blue);
    g2d.fillRect(00, s / 2, s / 2);
    g2d.setPaint(Color.green);
    g2d.fillRect(s / 20, s, s / 2);
    g2d.setPaint(Color.yellow);
    g2d.fillRect(0, s / 2, s / 2, s);
    g2d.setPaint(Color.red);
    g2d.fillRect(s / 2, s / 2, s, s);
  return bufferedImage;
  }
  public static void main(String[] args) {
    JFrame f = new JFrame("Text Textured Example");
    f.getContentPane().add(new TextTexturedExample());
    f.setSize(760200);
    f.show();
}
}

Output will be displayed as:

Download Source code

                         

» View all related tutorials
Related Tags: c memory image class images interface io colors sed color get implementation display icon height value source width int id

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.