// WythoffStarter.java // Class that allows the program to run under an applet. import java.awt.*; import java.awt.event.*; import java.applet.*; public class WythoffStarter extends Applet implements ActionListener { private Button start = new Button("Start Wythoff's Nim"); private WythoffApp wa = null; public void init() { start.setBackground(SystemColor.control); setBGColor(getParameter("background")); setLayout(new FlowLayout()); add(start); start.addActionListener(this); } public void close() { wa.stop(); wa.setVisible(false); wa.dispose(); wa = null; } public void actionPerformed(ActionEvent ae) { if (ae.getSource() == start) if (wa == null) wa = new WythoffApp(this, true); else wa.toFront(); } private void setBGColor(String background) { if ((background == null) || (background.length() != 7) || (background.charAt(0) != '#')) setBackground(Color.white); else { String hexcolor, red, green, blue; hexcolor = background.substring(1, background.length()); red = hexcolor.substring(0, 2); green = hexcolor.substring(2, 4); blue = hexcolor.substring(4, 6); setBackground(new Color(Integer.parseInt(red, 16), Integer.parseInt(green, 16), Integer.parseInt(blue, 16))); } } }