import javax.swing.*;

/**
 * This class represents an applet where the user can draw mosaics.
 */
public class MosaicDrawApplet extends JApplet {
	
	public void init() {
		int rows = getIntegerParameter("rows", 40);
		int cols = getIntegerParameter("columns", 40);
		MosaicPanel mosaic = new MosaicPanel(rows,cols);
		Controller controller = new Controller(mosaic);
		setJMenuBar(new Menus(controller,true));
		setContentPane(mosaic);
	}
	
	/**
	 * Gets an integer-valued parameter from an applet PARAM tag, if there is one and
	 * if the value is a legal integer.
	 * @param paramName the name of the parameter, from the NAME attribute of the PARAM tag
	 * @param defaultValue This value will be the return value of this method if there is no
	 * applet param with the specified name or if the VALUE attribute from the PARAM tag
	 * is not a legal integer.
	 */
	private int getIntegerParameter(String paramName, int defaultValue) {
		try {
			String param = getParameter(paramName);
			return Integer.parseInt(param);
		}
		catch (Exception e) {
			return defaultValue;
		}
	}

}
