import java.awt.*;
import javax.swing.*;

/** 
 * Demo of graphics methods.  Only the 
 * <code>paint</code> method is of interest.
 */
public class Canvas9 extends Canvas {
    
    public final String DEMO_STRING = "WinDOH!";

    public Canvas9() {
    }
    
    public void paint(Graphics g) {
	int w = this.getWidth();
	int h = this.getHeight();
	Graphics2D g2 = (Graphics2D) g;
	g2.scale(w/100,h/100);   // Set scale as 100x100.
	g2.translate(50,50);     // Set origin in center.
	g2.rotate(Math.PI/4);    // Rotate to corner-to-corner orientation.
	g.setColor(Color.red);
	g.fillRoundRect(-25,-25,50,50,10,10);
	g.setColor(Color.white);
	FontMetrics fm = g.getFontMetrics();
	int stringWidth = fm.stringWidth(DEMO_STRING);
	int fontAscent = fm.getAscent(); // standard height above baseline
	int fontDescent = fm.getDescent(); // standard dip below baseline
	g.drawString(DEMO_STRING,-stringWidth/2,(fontAscent-fontDescent)/2);
    }
    
    /** Test code */
    public static void main(String[] args) {
	JFrame f = new JFrame();
	Canvas9 c = new Canvas9();
	c.setSize(300,300);
	f.getContentPane().add(c);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
