Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/test/StarWidgetTest.java


1   package com.arranger.jarl.test;
2   
3   import com.arranger.jarl.util.IOUtil;
4   import com.arranger.jarl.util.RandomUtil;
5   
6   import java.awt.*;
7   import java.awt.geom.Ellipse2D;
8   import java.awt.geom.GeneralPath;
9   import java.io.File;
10  
11  /**
12   * StarWidgetTest created on Apr 5, 2003
13   */
14  public class StarWidgetTest extends TraitTest1 {
15  
16      protected double m_odds = .005;
17  
18      public void testStarWidget() throws Exception {
19  
20          m_imageWidth = 640;
21          m_imageHeight = 360;
22          Image image = createImage();
23          Graphics2D graphics2D = (Graphics2D) image.getGraphics();
24          paintStar(graphics2D);
25          IOUtil.save(image, new File("StarWidget.bmp"));
26      }
27  
28      protected void paintStar(Graphics2D graphics2D) {
29          graphics2D.setPaint(Color.blue);
30          GeneralPath generalPath = new GeneralPath();
31  
32          for (int y = 0; y < m_imageHeight; y++) {
33              for (int x = 0; x < m_imageWidth; x++) {
34                  if (RandomUtil.inRange(m_odds)) {
35                      generalPath.append(new Ellipse2D.Double(x, y, RandomUtil.getRandomRange(.5, 2.0), RandomUtil.getRandomRange(.5, 2.0)), false);
36                  }
37              }
38          }
39          graphics2D.fill(generalPath);
40      }
41  }