import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class MandelbrotUI extends Applet implements ActionListener, MouseListener, MouseMotionListener, ItemListener, WindowListener {
	private Button ivjButtonGenerate = null;
	private Label ivjLabelIterations = null;
	private Label ivjLabelIterationsValue = null;
	private Label ivjLabelXMax = null;
	private Label ivjLabelXMin = null;
	private Label ivjLabelYMax = null;
	private Label ivjLabelYMin = null;
	private Panel ivjPanelBody = null;
	private Panel ivjPanelMenu = null;
	private TextField ivjTextFieldXMax = null;
	private TextField ivjTextFieldXMin = null;
	private TextField ivjTextFieldYMax = null;
	private TextField ivjTextFieldYMin = null;
	private Button ivjButtonHelp = null;
	private Choice ivjChoiceColorScheme = null;
	private Choice ivjChoiceSampleRegions = null;
	private Label ivjLabelColorScheme = null;
	private Label ivjLabelSampleRegions = null;
	private static final int maxSize = 4;
	private int colorScheme;
	private int maxCol;
	private int maxRow;
	private int maxIterations = 512;
	private double P;
	private double Q[];
	private double XMax = 1.2d;
	private double XMin = -2.0d;
	private double YMax = 1.2d;
	private double YMin = -1.2d;

	private double[] arrXMin = { -2.0d, -0.702973d, -0.691594d, -0.691060d, -0.793114d, -0.749337d, -0.745465d, -0.745464d };

	private double[] arrXMax = { 1.2d, -0.642879d, -0.690089d, -0.690906d, -0.723005d, -0.744948d, -0.745387d, -0.745388d };

	private double[] arrYMin = { -1.2d, 0.374785d, 0.386608d, 0.387103d, 0.037822d, 0.109349d, 0.112896d, 0.112967d };

	private double[] arrYMax = { 1.2d, 0.395415d, 0.387494d, 0.387228d, 0.140974d, 0.115851d, 0.113034d, 0.113030d };

	private double deltaP;
	private double deltaQ;
	public final static String colors[] = { "FFFFFF", "0066CC", "0099CC", "66CCCC", "3333CC", "99CCFF", "00CCCC", "6699FF", "336699" };

	public final static String colors2[] =
		{
			"006600",
			"009900",
			"00CC00",
			"0099CF",
			"000000",
			"000066",
			"000099",
			"006600",
			"CC0000",
			"999900",
			"99CC33",
			"990033",
			"A1DFF8",
			"FF9900",
			"669933",
			"DDDEEE",
			"ADF3FF",
			"DFFFEE",
			"FFFFFF",
			"FFFF00",
			"AD00FF",
			"AFFF00",
			"660066",
			"CCFF99" };

	public final static String colors3[] = { "000000", "000066", "000099", "006600" };

	public final static String colors4[] = { "000000", "FFFFFF" };

	public final static String colors5[] = { "FF9900", "FFCC00", "FF6600" };

	private Graphics myGraphics;
	private Image image;

	public void buttonGenerate_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
		Graphics g = getPanelBody().getGraphics();
		colorScheme = getChoiceColorScheme().getSelectedIndex();

		// Clear
		g.clearRect(0, 0, maxCol, maxRow);

		// Get dimention values
		XMin = Double.parseDouble(getTextFieldXMin().getText());
		XMax = Double.parseDouble(getTextFieldXMax().getText());

		YMin = Double.parseDouble(getTextFieldYMin().getText());
		YMax = Double.parseDouble(getTextFieldYMax().getText());

		// Generate image
		generateImage(g);
	}
	/**
	 * Comment
	 */
	public void buttonHelp_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
		helpOn(getPanelBody().getGraphics());
	}
	/**
	 * connEtoC1:  (ButtonGenerate.action.actionPerformed(java.awt.event.ActionEvent) --> MandelbrotUI.buttonGenerate_ActionPerformed(Ljava.awt.event.ActionEvent;)V)
	 * @param arg1 java.awt.event.ActionEvent
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private void connEtoC1(java.awt.event.ActionEvent arg1) {
		try {
			// user code begin {1}
			// user code end
			this.buttonGenerate_ActionPerformed(arg1);
			// user code begin {2}
			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {3}
			// user code end
			handleException(ivjExc);
		}
	}
	/**
	 * connEtoC2:  (ButtonHelp.action.actionPerformed(java.awt.event.ActionEvent) --> MandelbrotUI.buttonHelp_ActionPerformed(Ljava.awt.event.ActionEvent;)V)
	 * @param arg1 java.awt.event.ActionEvent
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private void connEtoC2(java.awt.event.ActionEvent arg1) {
		try {
			// user code begin {1}
			// user code end
			this.buttonHelp_ActionPerformed(arg1);
			// user code begin {2}
			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {3}
			// user code end
			handleException(ivjExc);
		}
	}
	/**
	 * Cleans up whatever resources are being held. If the applet is active
	 * it is stopped.
	 * 
	 * @see #init
	 * @see #start
	 * @see #stop
	 */
	public void destroy() {
		super.destroy();

		// insert code to release resources here
	}
	/**
	 * Insert the method's description here.
	 * Creation date: (09/10/2002 4:03:34 PM)
	 * @author: Jose Sandoval
	 * @param g java.awt.Graphics
	 */
	private void generateImage(Graphics g) {
		double X = 0.0d;
		double Y = 0.0d;
		double Xsquare = 0.0d;
		double Ysquare = 0.0d;
		int color = 0;

		int maxColor = maxIterations;

		resetPQ();

		for (int col = 0; col < maxCol; col++) {
			for (int row = 0; row < maxRow; row++) {
				X = 0.0d;
				Y = 0.0d;
				Xsquare = 0.0d;
				Ysquare = 0.0d;
				color = 0;
				while ((color < maxIterations) && ((Xsquare + Ysquare) < maxSize)) {
					Xsquare = X * X;
					Ysquare = Y * Y;
					Y *= X;
					Y += Y + Q[row];
					X = Xsquare - Ysquare + P;
					color++;
				}

				if (0 == colorScheme) {
					// Traditional...
					g.setColor(new java.awt.Color(Integer.parseInt(colors[color % colors.length], 16)));
				} else if (1 == colorScheme) {
					g.setColor(new java.awt.Color(Integer.parseInt(colors3[color % colors3.length], 16)));
				} else if (2 == colorScheme) {
					// Trully random
					g.setColor(new java.awt.Color(Integer.parseInt(colors2[color % colors2.length], 16)));
				} else if (3 == colorScheme) {
					g.setColor(new java.awt.Color(Integer.parseInt(colors4[color % colors4.length], 16)));
				} else if (4 == colorScheme) {
					g.setColor(new java.awt.Color(Integer.parseInt(colors5[color % colors5.length], 16)));
				}
				g.fillOval(col, row, 1, 1);
			}
			P += deltaP;
		}
	}
	/**
	 * Returns information about this applet.
	 * @return a string of information about this applet
	 */
	public String getAppletInfo() {
		return "MandelbrotUI\n" + "\n" + "Generates Mandelbrot sets.\n" + "Creation date: (09/10/2002 3:17:08 PM)\n" + "@author: Jose Sandoval\n" + "";
	}
	/**
	 * Return the ButtonGenerate property value.
	 * @return java.awt.Button
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Button getButtonGenerate() {
		if (ivjButtonGenerate == null) {
			try {
				ivjButtonGenerate = new java.awt.Button();
				ivjButtonGenerate.setName("ButtonGenerate");
				ivjButtonGenerate.setLabel("Generate");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjButtonGenerate;
	}
	/**
	 * Return the ButtonHelp property value.
	 * @return java.awt.Button
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Button getButtonHelp() {
		if (ivjButtonHelp == null) {
			try {
				ivjButtonHelp = new java.awt.Button();
				ivjButtonHelp.setName("ButtonHelp");
				ivjButtonHelp.setLabel("Help");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjButtonHelp;
	}
	/**
	 * Return the Choice1 property value.
	 * @return java.awt.Choice
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Choice getChoiceColorScheme() {
		if (ivjChoiceColorScheme == null) {
			try {
				ivjChoiceColorScheme = new java.awt.Choice();
				ivjChoiceColorScheme.setName("ChoiceColorScheme");
				ivjChoiceColorScheme.setFont(new java.awt.Font("dialog", 0, 10));
				// user code begin {1}
				ivjChoiceColorScheme.add("Original");
				ivjChoiceColorScheme.add("16 colors");
				ivjChoiceColorScheme.add("24 Colors");
				ivjChoiceColorScheme.add("Black and White");
				ivjChoiceColorScheme.add("Orange Hue");
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjChoiceColorScheme;
	}
	/**
	 * Return the Choice2 property value.
	 * @return java.awt.Choice
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Choice getChoiceSampleRegions() {
		if (ivjChoiceSampleRegions == null) {
			try {
				ivjChoiceSampleRegions = new java.awt.Choice();
				ivjChoiceSampleRegions.setName("ChoiceSampleRegions");
				ivjChoiceSampleRegions.setFont(new java.awt.Font("dialog", 0, 10));
				// user code begin {1}
				ivjChoiceSampleRegions.add("Default");
				ivjChoiceSampleRegions.add("Zoom 1");
				ivjChoiceSampleRegions.add("Zoom 2");
				ivjChoiceSampleRegions.add("Zoom 3");
				ivjChoiceSampleRegions.add("Zoom 4");
				ivjChoiceSampleRegions.add("Zoom 5");
				ivjChoiceSampleRegions.add("Zoom 6");
				ivjChoiceSampleRegions.add("Zoom 7");
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjChoiceSampleRegions;
	}
	/**
	 * Return the Label1 property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelColorScheme() {
		if (ivjLabelColorScheme == null) {
			try {
				ivjLabelColorScheme = new java.awt.Label();
				ivjLabelColorScheme.setName("LabelColorScheme");
				ivjLabelColorScheme.setAlignment(java.awt.Label.RIGHT);
				ivjLabelColorScheme.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelColorScheme.setText("Color Scheme:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelColorScheme;
	}
	/**
	 * Return the LabelIterations property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelIterations() {
		if (ivjLabelIterations == null) {
			try {
				ivjLabelIterations = new java.awt.Label();
				ivjLabelIterations.setName("LabelIterations");
				ivjLabelIterations.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelIterations.setText("No. of Iterations:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelIterations;
	}
	/**
	 * Return the LabelIterationsValue property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelIterationsValue() {
		if (ivjLabelIterationsValue == null) {
			try {
				ivjLabelIterationsValue = new java.awt.Label();
				ivjLabelIterationsValue.setName("LabelIterationsValue");
				ivjLabelIterationsValue.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelIterationsValue.setText("512");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelIterationsValue;
	}
	/**
	 * Return the Label2 property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelSampleRegions() {
		if (ivjLabelSampleRegions == null) {
			try {
				ivjLabelSampleRegions = new java.awt.Label();
				ivjLabelSampleRegions.setName("LabelSampleRegions");
				ivjLabelSampleRegions.setAlignment(java.awt.Label.RIGHT);
				ivjLabelSampleRegions.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelSampleRegions.setText("Sample Regions:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelSampleRegions;
	}
	/**
	 * Return the LabelXMax property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelXMax() {
		if (ivjLabelXMax == null) {
			try {
				ivjLabelXMax = new java.awt.Label();
				ivjLabelXMax.setName("LabelXMax");
				ivjLabelXMax.setAlignment(java.awt.Label.RIGHT);
				ivjLabelXMax.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelXMax.setText("X Max:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelXMax;
	}
	/**
	 * Return the LabelXMin property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelXMin() {
		if (ivjLabelXMin == null) {
			try {
				ivjLabelXMin = new java.awt.Label();
				ivjLabelXMin.setName("LabelXMin");
				ivjLabelXMin.setAlignment(java.awt.Label.RIGHT);
				ivjLabelXMin.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelXMin.setText("X Min:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelXMin;
	}
	/**
	 * Return the LabelYMax property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelYMax() {
		if (ivjLabelYMax == null) {
			try {
				ivjLabelYMax = new java.awt.Label();
				ivjLabelYMax.setName("LabelYMax");
				ivjLabelYMax.setAlignment(java.awt.Label.RIGHT);
				ivjLabelYMax.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelYMax.setText("Y Max:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelYMax;
	}
	/**
	 * Return the LabelYMin property value.
	 * @return java.awt.Label
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Label getLabelYMin() {
		if (ivjLabelYMin == null) {
			try {
				ivjLabelYMin = new java.awt.Label();
				ivjLabelYMin.setName("LabelYMin");
				ivjLabelYMin.setAlignment(java.awt.Label.RIGHT);
				ivjLabelYMin.setFont(new java.awt.Font("dialog", 0, 10));
				ivjLabelYMin.setText("Y Min:");
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjLabelYMin;
	}
	/**
	 * Return the PanelBody property value.
	 * @return java.awt.Panel
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Panel getPanelBody() {
		if (ivjPanelBody == null) {
			try {
				ivjPanelBody = new java.awt.Panel();
				ivjPanelBody.setName("PanelBody");
				ivjPanelBody.setLayout(new java.awt.CardLayout());
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjPanelBody;
	}
	/**
	 * Return the PanelMenu property value.
	 * @return java.awt.Panel
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.Panel getPanelMenu() {
		if (ivjPanelMenu == null) {
			try {
				ivjPanelMenu = new java.awt.Panel();
				ivjPanelMenu.setName("PanelMenu");
				ivjPanelMenu.setLayout(new java.awt.GridBagLayout());

				java.awt.GridBagConstraints constraintsTextFieldXMin = new java.awt.GridBagConstraints();
				constraintsTextFieldXMin.gridx = 1;
				constraintsTextFieldXMin.gridy = 1;
				constraintsTextFieldXMin.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsTextFieldXMin.anchor = java.awt.GridBagConstraints.WEST;
				constraintsTextFieldXMin.weightx = 1.0;
				constraintsTextFieldXMin.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getTextFieldXMin(), constraintsTextFieldXMin);

				java.awt.GridBagConstraints constraintsTextFieldXMax = new java.awt.GridBagConstraints();
				constraintsTextFieldXMax.gridx = 1;
				constraintsTextFieldXMax.gridy = 2;
				constraintsTextFieldXMax.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsTextFieldXMax.anchor = java.awt.GridBagConstraints.WEST;
				constraintsTextFieldXMax.weightx = 1.0;
				constraintsTextFieldXMax.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getTextFieldXMax(), constraintsTextFieldXMax);

				java.awt.GridBagConstraints constraintsTextFieldYMin = new java.awt.GridBagConstraints();
				constraintsTextFieldYMin.gridx = 3;
				constraintsTextFieldYMin.gridy = 1;
				constraintsTextFieldYMin.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsTextFieldYMin.anchor = java.awt.GridBagConstraints.WEST;
				constraintsTextFieldYMin.weightx = 1.0;
				constraintsTextFieldYMin.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getTextFieldYMin(), constraintsTextFieldYMin);

				java.awt.GridBagConstraints constraintsTextFieldYMax = new java.awt.GridBagConstraints();
				constraintsTextFieldYMax.gridx = 3;
				constraintsTextFieldYMax.gridy = 2;
				constraintsTextFieldYMax.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsTextFieldYMax.anchor = java.awt.GridBagConstraints.WEST;
				constraintsTextFieldYMax.weightx = 1.0;
				constraintsTextFieldYMax.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getTextFieldYMax(), constraintsTextFieldYMax);

				java.awt.GridBagConstraints constraintsLabelXMin = new java.awt.GridBagConstraints();
				constraintsLabelXMin.gridx = 0;
				constraintsLabelXMin.gridy = 1;
				constraintsLabelXMin.anchor = java.awt.GridBagConstraints.EAST;
				constraintsLabelXMin.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getLabelXMin(), constraintsLabelXMin);

				java.awt.GridBagConstraints constraintsLabelXMax = new java.awt.GridBagConstraints();
				constraintsLabelXMax.gridx = 0;
				constraintsLabelXMax.gridy = 2;
				constraintsLabelXMax.anchor = java.awt.GridBagConstraints.EAST;
				constraintsLabelXMax.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getLabelXMax(), constraintsLabelXMax);

				java.awt.GridBagConstraints constraintsLabelYMin = new java.awt.GridBagConstraints();
				constraintsLabelYMin.gridx = 2;
				constraintsLabelYMin.gridy = 1;
				constraintsLabelYMin.anchor = java.awt.GridBagConstraints.EAST;
				constraintsLabelYMin.insets = new java.awt.Insets(8, 4, 8, 4);
				getPanelMenu().add(getLabelYMin(), constraintsLabelYMin);

				java.awt.GridBagConstraints constraintsLabelYMax = new java.awt.GridBagConstraints();
				constraintsLabelYMax.gridx = 2;
				constraintsLabelYMax.gridy = 2;
				constraintsLabelYMax.anchor = java.awt.GridBagConstraints.EAST;
				constraintsLabelYMax.insets = new java.awt.Insets(8, 4, 8, 4);
				getPanelMenu().add(getLabelYMax(), constraintsLabelYMax);

				java.awt.GridBagConstraints constraintsLabelIterations = new java.awt.GridBagConstraints();
				constraintsLabelIterations.gridx = 4;
				constraintsLabelIterations.gridy = 0;
				constraintsLabelIterations.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getLabelIterations(), constraintsLabelIterations);

				java.awt.GridBagConstraints constraintsLabelIterationsValue = new java.awt.GridBagConstraints();
				constraintsLabelIterationsValue.gridx = 5;
				constraintsLabelIterationsValue.gridy = 0;
				constraintsLabelIterationsValue.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getLabelIterationsValue(), constraintsLabelIterationsValue);

				java.awt.GridBagConstraints constraintsButtonGenerate = new java.awt.GridBagConstraints();
				constraintsButtonGenerate.gridx = 4;
				constraintsButtonGenerate.gridy = 2;
				constraintsButtonGenerate.gridwidth = 2;
				constraintsButtonGenerate.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsButtonGenerate.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getButtonGenerate(), constraintsButtonGenerate);

				java.awt.GridBagConstraints constraintsChoiceColorScheme = new java.awt.GridBagConstraints();
				constraintsChoiceColorScheme.gridx = 1;
				constraintsChoiceColorScheme.gridy = 0;
				constraintsChoiceColorScheme.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsChoiceColorScheme.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getChoiceColorScheme(), constraintsChoiceColorScheme);

				java.awt.GridBagConstraints constraintsLabelColorScheme = new java.awt.GridBagConstraints();
				constraintsLabelColorScheme.gridx = 0;
				constraintsLabelColorScheme.gridy = 0;
				constraintsLabelColorScheme.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getLabelColorScheme(), constraintsLabelColorScheme);

				java.awt.GridBagConstraints constraintsLabelSampleRegions = new java.awt.GridBagConstraints();
				constraintsLabelSampleRegions.gridx = 2;
				constraintsLabelSampleRegions.gridy = 0;
				constraintsLabelSampleRegions.anchor = java.awt.GridBagConstraints.EAST;
				constraintsLabelSampleRegions.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getLabelSampleRegions(), constraintsLabelSampleRegions);

				java.awt.GridBagConstraints constraintsChoiceSampleRegions = new java.awt.GridBagConstraints();
				constraintsChoiceSampleRegions.gridx = 3;
				constraintsChoiceSampleRegions.gridy = 0;
				constraintsChoiceSampleRegions.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsChoiceSampleRegions.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getChoiceSampleRegions(), constraintsChoiceSampleRegions);

				java.awt.GridBagConstraints constraintsButtonHelp = new java.awt.GridBagConstraints();
				constraintsButtonHelp.gridx = 4;
				constraintsButtonHelp.gridy = 1;
				constraintsButtonHelp.gridwidth = 2;
				constraintsButtonHelp.fill = java.awt.GridBagConstraints.HORIZONTAL;
				constraintsButtonHelp.insets = new java.awt.Insets(4, 4, 4, 4);
				getPanelMenu().add(getButtonHelp(), constraintsButtonHelp);
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjPanelMenu;
	}
	/**
	 * Return the TextFieldXMax property value.
	 * @return java.awt.TextField
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.TextField getTextFieldXMax() {
		if (ivjTextFieldXMax == null) {
			try {
				ivjTextFieldXMax = new java.awt.TextField();
				ivjTextFieldXMax.setName("TextFieldXMax");
				ivjTextFieldXMax.setFont(new java.awt.Font("dialog", 0, 10));
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjTextFieldXMax;
	}
	/**
	 * Return the TextFieldXMin property value.
	 * @return java.awt.TextField
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.TextField getTextFieldXMin() {
		if (ivjTextFieldXMin == null) {
			try {
				ivjTextFieldXMin = new java.awt.TextField();
				ivjTextFieldXMin.setName("TextFieldXMin");
				ivjTextFieldXMin.setFont(new java.awt.Font("dialog", 0, 10));
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjTextFieldXMin;
	}
	/**
	 * Return the TextFieldYMax property value.
	 * @return java.awt.TextField
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.TextField getTextFieldYMax() {
		if (ivjTextFieldYMax == null) {
			try {
				ivjTextFieldYMax = new java.awt.TextField();
				ivjTextFieldYMax.setName("TextFieldYMax");
				ivjTextFieldYMax.setFont(new java.awt.Font("dialog", 0, 10));
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjTextFieldYMax;
	}
	/**
	 * Return the TextFieldYMin property value.
	 * @return java.awt.TextField
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private java.awt.TextField getTextFieldYMin() {
		if (ivjTextFieldYMin == null) {
			try {
				ivjTextFieldYMin = new java.awt.TextField();
				ivjTextFieldYMin.setName("TextFieldYMin");
				ivjTextFieldYMin.setFont(new java.awt.Font("dialog", 0, 10));
				// user code begin {1}
				// user code end
			} catch (java.lang.Throwable ivjExc) {
				// user code begin {2}
				// user code end
				handleException(ivjExc);
			}
		}
		return ivjTextFieldYMin;
	}
	/**
	 * Called whenever the part throws an exception.
	 * @param exception java.lang.Throwable
	 */
	private void handleException(java.lang.Throwable exception) {

		/* Uncomment the following lines to print uncaught exceptions to stdout */
		// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
		// exception.printStackTrace(System.out);
	}
	/**
	 * Insert the method's description here.
	 * Creation date: (09/10/2002 6:38:55 PM)
	 * @author: Jose Sandoval
	 */
	public void helpOn(Graphics g) {
		int x = 40;
		int y = 20;
		g.clearRect(0, 0, maxCol, maxRow);

		g.setColor(Color.gray);
		g.drawRect(10, 10, 620, 460);

		g.setColor(Color.black);
		g.drawString("MandelbrotUI v1.0 - Jose Sandoval - (c) October 2002", x, 60);
		g.drawString("The applet generates the Mandelbrot set.", x, 80);

		g.setColor(Color.red);
		g.drawString("Instructions:", x, y + 100);

		g.setColor(Color.black);
		g.drawString("Color Scheme - Holds values for predefined color schemes", x, y + 120);
		g.drawString("Sample Regions - Holds values for predefined interesting (I think) regions of the set", x, y + 140);
		g.drawString("Rectangle co-ordinates: (XMin, YMin), (XMax, YMax)", x, y + 160);
		g.drawString("Help - Displays this help", x, y + 180);
		g.drawString("Generate - Generates the Mandelbrot set with parameters entered", x, y + 200);
	}
	/**
	 * Initializes the applet.
	 */
	public void init() {
		try {
			super.init();
			setName("MandelbrotUI");
			setLayout(new java.awt.BorderLayout());
			setSize(640, 600);
			add(getPanelMenu(), "North");
			add(getPanelBody(), "Center");
			initConnections();
			// user code begin {1}
			//maxCol = getPanelBody().getSize().width;
			//maxRow = getPanelBody().getSize().height;
			maxCol = 640;
			maxRow = 480;

			// Buffered image
			image = createImage(maxCol, maxRow);
			myGraphics = image.getGraphics();

			// Take care of UI
			getLabelIterationsValue().setText("" + maxIterations);
			getTextFieldXMin().setText("" + XMin);
			getTextFieldXMax().setText("" + XMax);
			getTextFieldYMin().setText("" + YMin);
			getTextFieldYMax().setText("" + YMax);

			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {2}
			// user code end
			handleException(ivjExc);
		}
	}
	/**
	 * Initializes connections
	 * @exception java.lang.Exception The exception description.
	 */
	/* WARNING: THIS METHOD WILL BE REGENERATED. */
	private void initConnections() throws java.lang.Exception {
		// user code begin {1}
		getChoiceSampleRegions().addItemListener(this);
		// user code end
		getButtonGenerate().addActionListener(this);
		getButtonHelp().addActionListener(this);
	}
	/**
	 * Invoked when an item has been selected or deselected.
	 * The code written for this method performs the operations
	 * that need to occur when an item is selected (or deselected).
	 */
	public void itemStateChanged(java.awt.event.ItemEvent e) {
		int whichRegion = getChoiceSampleRegions().getSelectedIndex();

		// Set values
		getTextFieldXMin().setText("" + arrXMin[whichRegion]);
		getTextFieldXMax().setText("" + arrXMax[whichRegion]);
		getTextFieldYMin().setText("" + arrYMin[whichRegion]);
		getTextFieldYMax().setText("" + arrYMax[whichRegion]);
	}
	/**
	 * Starts the applet when it is run as an application
	 * @param args an array of command-line arguments
	 */
	public static void main(java.lang.String[] args) {
		MandelbrotUI applet = new MandelbrotUI();
		java.awt.Frame frame = new java.awt.Frame("Applet");

		frame.addWindowListener(applet);
		frame.add("Center", applet);
		frame.setSize(350, 250);
		frame.show();

		applet.init();
		applet.start();
	}
	/**
	 * Called when the mouse has been clicked.
	 * @param e the received event
	 */
	public void mouseClicked(MouseEvent e) {
		System.out.println("mouseClicked");
	}
	/**
	 * Called when the mouse has been dragged.
	 * @param e the received event
	 */
	public void mouseDragged(MouseEvent e) {
		System.out.println("mouseDragged");
	}
	/**
	 * Called when the mouse has entered a window.
	 * @param e the received event
	 */
	public void mouseEntered(MouseEvent e) {
		System.out.println("mouseEntered");
	}
	/**
	 * Called when the mouse has exited a window.
	 * @param e the received event
	 */
	public void mouseExited(MouseEvent e) {
		System.out.println("mouseExited");
	}
	/**
	 * Called when the mouse has been moved.
	 * @param e the received event
	 */
	public void mouseMoved(MouseEvent e) {
		System.out.println("mouseMoved");
	}
	/**
	 * Called when a mouse button has been pressed.
	 * @param e the received event
	 */
	public void mousePressed(MouseEvent e) {
		System.out.println("mousePressed");
	}
	/**
	 * Called when a mouse button has been released.
	 * @param e the received event
	 */
	public void mouseReleased(MouseEvent e) {
		System.out.println("mouseReleased");
	}
	/**
	 * Paints the applet.
	 * If the applet does not need to be painted (e.g. if it is only a container for other
	 * awt components) then this method can be safely removed.
	 * 
	 * @param g  the specified Graphics window
	 * @see #update
	 */
	public void paint(Graphics g) {
		super.paint(g);
	}
	/**
	 * Insert the method's description here.
	 * Creation date: (09/10/2002 4:10:08 PM)
	 * @author: Jose Sandoval
	 */
	public void resetPQ() {
		Q = new double[maxRow];

		deltaP = (double) ((XMax - XMin) / maxCol);
		deltaQ = (double) ((YMax - YMin) / maxRow);
		P = XMin;

		Q[0] = YMax;
		for (int row = 1; row < maxRow; row++) {
			Q[row] = Q[row - 1] - deltaQ;
		}
	}
	/**
	 * Invoked when a window is activated.
	 * @param e the received event
	 */
	public void windowActivated(WindowEvent e) {
		// Do nothing.
		// This method is required to comply with the WindowListener interface.
	}
	/**
	 * Invoked when a window has been closed.
	 * @param e the received event
	 */
	public void windowClosed(WindowEvent e) {
		// Do nothing.
		// This method is required to comply with the WindowListener interface.
	}
	/**
	 * Invoked when a window is in the process of being closed.
	 * The close operation can be overridden at this point.
	 * @param e the received event
	 */
	public void windowClosing(WindowEvent e) {
		// The window is being closed.  Shut down the system.
		System.exit(0);
	}
	/**
	 * Invoked when a window is deactivated.
	 * @param e the received event
	 */
	public void windowDeactivated(WindowEvent e) {
		// Do nothing.
		// This method is required to comply with the WindowListener interface.
	}
	/**
	 * Invoked when a window is de-iconified.
	 * @param e the received event
	 */
	public void windowDeiconified(WindowEvent e) {
		// Do nothing.
		// This method is required to comply with the WindowListener interface.
	}
	/**
	 * Invoked when a window is iconified.
	 * @param e the received event
	 */
	public void windowIconified(WindowEvent e) {
		// Do nothing.
		// This method is required to comply with the WindowListener interface.
	}
	/**
	 * Invoked when a window has been opened.
	 * @param e the received event
	 */
	public void windowOpened(WindowEvent e) {
		// Do nothing.
		// This method is required to comply with the WindowListener interface.
	}

	public void actionPerformed(java.awt.event.ActionEvent e) {
			if (e.getSource() == MandelbrotUI.this.getButtonGenerate())
				connEtoC1(e);
			if (e.getSource() == MandelbrotUI.this.getButtonHelp())
				connEtoC2(e);
	}
}
Syntax Highlighting created using the com.Ostermiller.Syntax package.
Friday, January 03 2003 at 21:48