package awb; import java.awt.*; import java.util.*; public class Utilities { // returns a number: low <= num < high. low and high must // be nonnegative or it will return 0 private static java.util.Random generator; public static int getRandomInt(int low, int high) { if (generator == null) generator = new java.util.Random(); if (low == high) return low; if (low > high) { int t = low; low = high; high = t; } if (low < 0) return 0; int range = high - low; int temp = generator.nextInt() % range; if (temp < 0) return temp * -1; else return temp; } public static void pause(int howLong) { try { Thread.sleep(howLong); } catch (InterruptedException ex) { } } public static void start(Runnable r) { Thread t = new Thread(r); t.start(); } public static String wrap(String data, int width, FontMetrics fm) { StringTokenizer stok = new StringTokenizer(data, " \n", true); data = ""; String next, line = ""; while (stok.hasMoreTokens()) try { next = stok.nextToken(); line += next; if (fm.stringWidth(line) > width) { data += "\n"; line = next; } if (line.endsWith("\n")) line = ""; // System.out.println("next: -" + next + // "-\nline: " + line + "\n\n"); data += next; } catch (NoSuchElementException e) { } return data; } }