package org.quiz; import java.awt.*; import java.applet.*; public class QuizApplet extends Applet { public static final Color DEFAULT_BACKGROUND = Color.white; public void init() { super.init(); setBackground(getBackgroundColor(DEFAULT_BACKGROUND)); } protected Color getBackgroundColor(Color defaultColor) { Color c = defaultColor; String stringColor = getParameter("background"); if (stringColor != null) { if (stringColor.startsWith("#") && stringColor.length() > 1) { try { c = new Color(Integer.parseInt(stringColor.substring(1), 16)); } catch(NumberFormatException e) { } } } return c; } // This is a helper class, to extract the integer // in the input. // The assumption is that integer value // is followed by non digits, in some cases ('X'). // So it supposed to read the integer, and ignore // the rest. public String getInt(String s){ String r= ""; int i = 0; int l = s.length(); char c; if (s == null || s.length() == 0 ) return ""; while (s.charAt(i) == ' ') i++; if (s.charAt(i) == '-' ){ r = r+s.charAt(i); i++; } if (s.charAt(i) == '+') i++; while (i < l){ c = s.charAt(i); if (Character.isDigit(c)){ r = r+c; } else break; i++; } return r; } }