Пример #1
0
 // Generate n components of random sizes
 public static JComponent[] generateRandomComponents(int n) {
   Random r = new Random(0);
   JComponent[] c = new JComponent[n];
   int m = n;
   while (m > 0) {
     int i = r.nextInt(n);
     if (c[i] == null) {
       c[i] = new JLabel("Component " + i, null, SwingConstants.CENTER);
       int w = 5 * (2 + r.nextInt(20));
       int h = 5 * (2 + r.nextInt(20));
       c[i].setPreferredSize(new Dimension(w, h));
       c[i].setBorder(new EtchedBorder());
       m--;
     }
   }
   return c;
 }
Пример #2
0
 public void nudge(int i) {
   x[i] += (double) rand.nextInt(1000) / 8756;
   y[i] += (double) rand.nextInt(1000) / 5432;
   int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10);
   scale[i] = (double) tmpScale / 10;
   int nudgeX = (int) (((double) getWidth() / 2) * .8);
   int nudgeY = (int) (((double) getHeight() / 2) * .60);
   xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX;
   yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY;
 }
 private static String generatePassword() {
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < 4; i++) sb.append((char) (random.nextInt(26) + 'a'));
   return new String(sb);
 }