import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

/** 
 * Demo of graphics methods.  Only the 
 * <code>paint</code> methods are of interest.
 */
public class Button1 extends JButton {
    
    public String demoString = "WinDOH!";

    public Button1() {
    }

    public Button1(String text) {
	demoString = text;
    }
    
    protected void paintComponent(Graphics g) {
	int w = this.getWidth();
	int h = this.getHeight();
	Graphics2D g2 = (Graphics2D) g;
	// Notice that without this statement, the border is not drawn
	// and the button does not highlight when selected.
	super.paintComponent(g);
	g2.rotate(Math.PI/6,w/2,h/2);
	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(demoString);
	int fontAscent = fm.getAscent(); // standard height above baseline
	int fontDescent = fm.getDescent(); // standard dip below baseline
	g.drawString(demoString,(w-stringWidth)/2,(h+fontAscent-fontDescent)/2);
	// Notice that without this statement, the border is also rotated.
	// This resets the identity transformation.
	g2.setTransform(new AffineTransform()); 
    }
    
    /** Test code */
    public static void main(String[] args) {
	JFrame f = new JFrame();
	Button1 b = new Button1();
	b.setSize(300,300);
	f.getContentPane().add(b);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
