TexturedTextpublic class TexturedText extends JComponent
Fields Summary |
---|
protected BufferedImage | bimThe image we draw in the texture | TexturePaint | tpThe texture for painting. | String | mesgThe string to draw. | Font | myFontThe 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.Dimension | getMinimumSize()
return new Dimension(250, 100);
| public java.awt.Dimension | getPreferredSize()
return new Dimension(320, 150);
| public static void | main(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 void | paint(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);
|
|