import java.awt.*;
import javax.swing.*;

/** 
 * Demo of graphics methods.  Only the 
 * <code>paint</code> method is of interest.
 */
public class NewCanvas2 extends Canvas {
    
    public final String DEMO_STRING = "WinDOH!";

    public NewCanvas2() {
    }
    
    public void paint(Graphics g) {
	int w = this.getWidth();
	int h = this.getHeight();
	Graphics2D g2 = (Graphics2D) g;
	g2.rotate(Math.PI/6,w/2,h/2);
	g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	g.setColor(Color.red);
	g.fillRoundRect(w/4, h/4, w/2, h/2, w/10, h/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,(w-stringWidth)/2,(h+fontAscent-fontDescent)/2);
    }
    
    /** Test code */
    public static void main(String[] args) {
	JFrame f = new JFrame();
	NewCanvas2 c = new NewCanvas2();
	c.setSize(300,300);
	f.getContentPane().add(c);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
