Welcome to Dream.In.Code
Become a Java Expert!

Join 150,418 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,062 people online right now. Registration is fast and FREE... Join Now!




Rotating a shape

 
Reply to this topicStart new topic

Rotating a shape

Mastergeek666
17 Mar, 2008 - 07:05 PM
Post #1

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
Can someone tell me how to rotate a shape??? I have this program that creates a custom button but I want it to be rotated to look like a diamond.
Here's my code:
java

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class RoundButton extends JButton
{
public RoundButton(String label)
{
super(label);
Dimension size = getPreferredSize();
size.width = size.height = Math.max(size.width, size.height);
setPreferredSize(size);
setContentAreaFilled(false);
}
protected void paintComponent(Graphics g)
{
if(getModel().isArmed())
{
g.setColor(Color.lightGray);
}
else
{
g.setColor(getBackground());
}
g.fillRect(0,0,getSize().width - 1, getSize().height - 1);
super.paintComponent(g);
}
protected void paintBorder(Graphics g)
{
g.setColor(getForeground());
g.drawRect(0,0,getSize().width-1, getSize().height-1);
}
Shape shape;
public boolean contains(int x, int y)
{
if(shape == null || !shape.getBounds().equals(getBounds()))
{
shape = new Ellipse2D.Float(0,0,getWidth(), getHeight());
}
return shape.contains(x, y);
}
public static void main(String[] args)
{
JButton button = new RoundButton("Jackpot");
button.setBackground(Color.green);
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.yellow);
frame.getContentPane().add(button);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(150, 150);
frame.setVisible(true);
}
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:16PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month