import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class RoundFrame
{
public static void main(String[] args)
{
SwingUtilities.invokeLater
(
new Runnable()
{
@Override
public void run()
{
new RoundFrame("Going Round in Circles");
}
}
);
}
private RoundFrame(String title)
{
final JFrame frame = new JFrame(title);
frame.setUndecorated(true);
frame.setBounds(new Rectangle(400,200,700,700));
frame.setShape(new Ellipse2D.Double(0,0,700,700));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLayout(null);
JButton closeButton = new JButton("Close");
closeButton.setMnemonic('c');
closeButton.setBounds(450,550,80,25);
closeButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
frame.dispose();
}
});
frame.add(closeButton);
RoundPanel panel = new RoundPanel(350,3);
panel.setBackground(new Color(33,99,140));
frame.add(panel);
frame.setVisible(true);
}
private class RoundPanel extends JPanel
{
private int rpRadius = 1;
private int rpBorder = 1;
private RoundPanel(int radius)
{
super();
rpRadius = radius;
this.setBounds(0,0,rpRadius*2, rpRadius*2);
}
private RoundPanel(int radius, int border)
{
super();
rpRadius = radius;
rpBorder = border;
this.setBounds(0,0,rpRadius*2, rpRadius*2);
}
public int getRadius()
{
return rpRadius;
}
public int getDiameter()
{
return(rpRadius * 2);
}
public int getBorderThickness()
{
return rpBorder;
}
@Override protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.black);
for ( int i = 0; i < getBorderThickness(); i++)
{
g.drawOval(i, i, getDiameter()-(i*2), getDiameter()-(i*2));
}
g.setColor(Color.gray);
for ( int i = getBorderThickness(); i < 2 * getBorderThickness(); i++)
{
g.drawOval(i, i, getDiameter()-(i*2), getDiameter()-(i*2));
}
}
}
}