Tue Nov 11, 2008 7:34 pm
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(0, 0, bufferedImage.getWidth(),
bufferedImage.getHeight());
TexturePaint texturePaint = new TexturePaint(bufferedImage, rect);
g2d.setPaint(texturePaint);
g2d.drawString(st, 20, 100);
}
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(0, 0, s / 2, s / 2);
g2d.setPaint(Color.green);
g2d.fillRect(s / 2, 0, 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(760, 200);
f.show();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.