// A simple canvas class used by several different applets to display // the message "Hello World" in big, bold, colored type. A method is // provided for changing the color of the message. (This is used by // ColoredHelloWorldApplet2, BlinkingHelloWorld1, and BlinkingHelloWorld2.) import java.awt.*; class ColoredHelloWorldCanvas extends Canvas { // A canvas that displays the message "Hello World" on // a white background in a big, bold font. A method is // provided for changing the color of the message. Color textColor; // Color in which "Hello World" is displayed; // this changes when the user clicks on a button. Font textFont; // The font in which the message is displayed. ColoredHelloWorldCanvas() { // Constructor. setBackground(Color.white); textColor = Color.red; textFont = new Font("Serif",Font.BOLD,24); } public void paint(Graphics g) { // Show the message in the set color and font. g.setColor(textColor); g.setFont(textFont); g.drawString("Hello World!", 20,40); } void setTextColor(Color color) { // Set the text color and tell the system to repaint the canvas. textColor = color; repaint(); } } // end class ColoredHelloWorldCanvas