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 Button3 extends JButton {
    
    public String demoString = "WinDOH!";

    public Button3() {
    }

    public Button3(String text) {
	demoString = text;
    }
    
    protected void paintComponent(Graphics g) {
	int w = this.getWidth();
	int h = this.getHeight();
	Graphics2D g2 = (Graphics2D) g;

	// By rotating user space before calling the inherited method,
	// we can affect the way button highlighting appears too.
	g2.rotate(-Math.PI/6,w/2,h/2);   
	super.paintComponent(g);
	g2.rotate(Math.PI/6,w/2,h/2);
	// Note that this does not affect the actual location or size of 
	// the button for purposes of clicking.
	
	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()); 
    }
    
    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();
	Button3 b = new Button3();
	b.setSize(300,300);
	f.getContentPane().add(b);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
