Java Reference
In-Depth Information
TexturedText comp = new
new TexturedText ();
f . add ( comp );
f . addWindowListener ( new
new WindowAdapter () {
public
public void
void windowClosing ( WindowEvent e ) {
f . setVisible ( false
false );
f . dispose ();
System . exit ( 0 );
}
});
f . pack ();
f . setLocation ( 200 , 200 );
f . setVisible ( true
true );
}
protected
protected static
static Color [] colors = {
Color . red , Color . blue , Color . yellow ,
};
/** Construct the object */
public
public TexturedText () {
super
super ();
setBackground ( Color . white );
int
int width = 8 , height = 8 ;
bim = new
new BufferedImage ( width , height , BufferedImage . TYPE_INT_ARGB );
Graphics2D g2 = bim . createGraphics ();
for
for ( int
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
new Rectangle ( 0 , 0 , bim . getWidth (), bim . getHeight ());
tp = new
new TexturePaint ( bim , r );
}
@Override
public
public void
void paintComponent ( 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 );
}
@Override
public
public Dimension getMinimumSize () {
Search WWH ::




Custom Search