// PuzzleStarter.java // Class that allows the program to run under an applet. import java.awt.*; import java.awt.event.*; import java.applet.*; public class PuzzleStarter extends Applet implements ActionListener { private Button start = new Button("Start 8-Puzzle Solver"); private PuzzleApp pa = null; public void init() { start.setBackground(SystemColor.control); setBGColor(getParameter("background")); setLayout(new FlowLayout()); add(start); start.addActionListener(this); } public void close() { pa.stop(); pa.setVisible(false); pa.dispose(); pa = null; } public void actionPerformed(ActionEvent ae) { if (ae.getSource() == start) if (pa == null) pa = new PuzzleApp(this, true); else pa.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))); } } }