Example of
changing the colour of the current graphics context
Extending the previous example, we can create
an applet to draw blue text in its window to produce the following output:
by simply adding a statement to change the colour of the
graphics context before drawing the string.
So we must send a setColor() message to the Graphics object before sending the drawString() message:
import java.applet.Applet;
import java.awt.*;
public class DrawString2 extends
Applet
{
public void paint( Graphics
g )
{
g.setColor( Color.blue );
g.drawString( "text drawn with Graphics
method 'drawString()'",
20, 20 );
}
} // class
Back
to top

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights
reserved.
webmaster@globalcampus.com.eg
|