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

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




Help with shapes

 
Reply to this topicStart new topic

Help with shapes

Mastergeek666
16 Mar, 2008 - 07:51 PM
Post #1

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
Hi I have this program that creates a custom shape for a JButton, right now its just a rectangle, The question is can anyone help me with the math that will make the rectangle look like a diamond that looks tilted to make it look as if it is in an XYZ plane. Thanks in advance!!!

Here's program:
java

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.Polygon.*;
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);
}
}


This post has been edited by Mastergeek666: 16 Mar, 2008 - 07:52 PM
User is offlineProfile CardPM
+Quote Post

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

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