ColoredHelloWorldCanvas

ColoredHelloWorldCanvas - Font textFont; // The font in...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// 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.*; i class ColoredHelloWorldCanvas extends Canvas { c // 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.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 }...
View Full Document

This note was uploaded on 01/15/2010 for the course CSC 115 taught by Professor Jackson during the Spring '09 term at University of Victoria.

Ask a homework question - tutors are online