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 Button2 extends JButton {
    
    public String demoString = "WinDOH!";

    public Button2() {
    }

    public Button2(String text) {
	demoString = text;
    }
    
    protected void paintComponent(Graphics g) {
	int w = this.getWidth();
	int h = this.getHeight();
	Graphics2D g2 = (Graphics2D) g;
	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);
	g2.setTransform(new AffineTransform()); 
    }
    
    /** Overrides the default paintBorder method to create
	the illusion of an angled button */
    protected void paintBorder(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	int w = this.getWidth();
	int h = this.getHeight();
	g2.rotate(-Math.PI/6,w/2,h/2);
	super.paintBorder(g2);
	g2.rotate(Math.PI/6,w/2,h/2);	
    }

    /** Test code */
    public static void main(String[] args) {
	JFrame f = new JFrame();
	Button2 b = new Button2();
	b.setSize(300,300);
	f.getContentPane().add(b);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
