1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Graphics2D;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. 
  7. /**
  8. * Main.java
  9. * @author Jose M Vidal <jmvidal@gmail.com>
  10. * Created on Jan 23, 2012
  11. *
  12. */
  13. 
  14. public class Main extends JPanel {
  15. 
  16. public void paintComponent(Graphics g){
  17. final int centerX = 300; //the centerX and Y coordinates of our flower.
  18. final int centerY = 300;
  19. int ovalWidth = 100;
  20. Graphics2D g2 = (Graphics2D) g;
  21. 
  22. for (int ovalLength = 300; ovalLength > 25; ovalLength--) {
  23. if (ovalLength < 50) {
  24. g2.setColor(Color.yellow);
  25. }
  26. else {
  27. g2.setColor(Color.black);
  28. g2.fillOval(centerX -1 , centerY - ovalWidth / 2 - 1, (int)ovalLength + 2, ovalWidth + 2);
  29. if (ovalLength % 2 == 0)
  30. g2.setColor(Color.blue);
  31. else if (ovalLength % 2 == 1)
  32. g2.setColor(Color.cyan);
  33. }
  34. 
  35. g2.fillOval(centerX, centerY - ovalWidth / 2, (int)ovalLength, ovalWidth);
  36. g2.rotate(Math.toRadians(137.5), centerX,centerY );
  37. }
  38. }
  39. 
  40. /**
  41. * @param args
  42. */
  43. public static void main(String[] args) {
  44. JFrame frame = new JFrame("Window");
  45. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46. Main panel = new Main();
  47. 
  48. frame.add(panel);
  49. frame.setSize(640,640);
  50. frame.setVisible(true);
  51. 
  52. 
  53. }
  54. 
  55. }