FileDocCategorySizeDatePackage
TexturedText.javaAPI DocExample1990Sun Feb 08 21:33:50 GMT 2004None

TexturedText

public class TexturedText extends JComponent
Text with a Texture
author
Ian Darwin, http://www.darwinsys.com/
version
$Id: TexturedText.java,v 1.5 2004/02/09 03:33:49 ian Exp $

Fields Summary
protected BufferedImage
bim
The image we draw in the texture
TexturePaint
tp
The texture for painting.
String
mesg
The string to draw.
Font
myFont
The font
protected static Color[]
colors
Constructors Summary
public TexturedText()
Construct the object


	    
	  
		super();
		setBackground(Color.white);
		int width = 8, height = 8;
		bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2 = bim.createGraphics();
		for (int i=0; i<width; i++) {
			g2.setPaint(colors[(i/2)%colors.length]);
			g2.drawLine(0, i, i, 0);
			g2.drawLine(width-i, height, width, height-i);
		}
		Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
		tp = new TexturePaint(bim, r);
	
Methods Summary
public java.awt.DimensiongetMinimumSize()

	 	return new Dimension(250, 100);
	
public java.awt.DimensiongetPreferredSize()

	 	return new Dimension(320, 150);
	
public static voidmain(java.lang.String[] av)
"main program" method - construct and show


	        
	     
		// create a TexturedText object, tell it to show up
		final Frame f = new Frame("TexturedText");
		TexturedText comp = new TexturedText();
		f.add(comp);
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				f.setVisible(false);
				f.dispose();
				System.exit(0);
			}
		});
		f.pack();
		f.setLocation(200, 200);
		f.setVisible(true);
	
public voidpaint(java.awt.Graphics g)

		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setPaint(tp);
		g2.setFont(myFont);
		g2.drawString(mesg, 20, 100);