Assorted API hints

Random numbers

You can (pseudo-)randomly generate integers using the nextInt method in the built-in java.util.Random class.

For example,

  import java.util.Random;

  class RandomTest {
    public static void main(String[] as) {
      Random  randomSource = new Random();

      if (as.length == 0)  as = new String[] { "alpha", "beta", "gamma" };

      final int trials = 100;

      for (int i = 0; i < trials; i ++) {
        // choose a random integer between 0 and as.length - 1 (inclusive)...
        final int j = randomSource.nextInt(as.length);

        // print a randomly selected element of as...
        System.out.println(as[j]);
      }
    }
  }

Painting / Graphics

Please see the Working with Graphics lesson in sun's java tutorial.

Animation

Please see the Performing Animation section of the Working with Graphics lesson in sun's java tutorial.

Various widgets