|
用Applet写的菜单程序 machine(3) if (fm.getHeight() <= fh) { break; } i--; }
// Get the menu parameters. for (i=0; ; i++) { if (getParameter("menu"+i) == null) { hitArea = new Rectangle[i]; srcRect = new Rectangle[i]; dstPt = new Point[i]; url = new String[i]; down = new boolean[i]; itemUrl = new String[i][]; item = new String[i][];
break; } }
for (i=0; i String[] fields = parse(getParameter("menu"+i), getParameter("separ ator")); // Get the hit area. ints = parseInt(fields[0], " "); hitArea[i] = new Rectangle(ints[0], ints[1], ints[2], ints[3]);
// Get the source image. ints = parseInt(fields[1], " "); srcRect[i] = new Rectangle(ints[0], ints[1], ints[2], ints[3]);
// Get the destination point. ints = parseInt(fields[2], " "); dstPt[i] = new Point(ints[0], ints[1]); down[i] = fields[3].equals("d"); url[i] = fields[4];
item[i] = new String[(fields.length-5)/2]; itemUrl[i] = new String[(fields.length-5)/2]; for (int j=0; j- item[i][j] = fields[j*2+5];
itemUrl[i][j] = fields[j*2+6]; } } }
// s is a string containing 'sep' separators. This method // breaks up the string at the separators and returns the resulting // strings in an array. The result may have zero length but is never null. String[] parse(String s, String sep) { StringTokenizer st = new StringTokenizer(s, sep); String result[] = new String[st.countTokens()];
for (int i=0; i result[i] = st.nextToken(); } return result; }
// This method is similar to parse() except that the strings are // assumed to be decimal integers. This method coverts these integer // strings into integers and returns them in an array. // The result may have zero length but is never null. int[] parseInt(String s, String sep) { StringTokenizer st = new StringTokenizer(s, sep);
|