// DisplayMessageApplet.java: Generated from the Applet wizard
package chapter12;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import chapter10.MessagePanel;

public class DisplayMessageApplet extends JApplet
{
  boolean isStandalone = false;
  String message;
  int x;
  int y;

  /**Get a parameter value*/
  public String getParameter(String key, String def)
  {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }

  /**Construct the applet*/
  public DisplayMessageApplet()
  {
  }

  /**Initialize the applet*/
  public void init()
  {
    try
    {
      message = this.getParameter("MESSAGE", "Welcome to Java");
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    try
    {
      x = Integer.parseInt(this.getParameter("X", "40"));
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    try
    {
      y = Integer.parseInt(this.getParameter("Y", "40"));
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  /**Component initialization*/
  private void jbInit() throws Exception
  {
    this.setSize(new Dimension(400,300));
    MessagePanel messagePanel = new MessagePanel(message);
    messagePanel.setXCoordinate(x);
    messagePanel.setYCoordinate(y);
    getContentPane().add(messagePanel, BorderLayout.CENTER);
    messagePanel.repaint();
  }

  /**Get Applet information*/
  public String getAppletInfo()
  {
    return "Applet Information";
  }

  /**Get parameter info*/
  public String[][] getParameterInfo()
  {
    String[][] pinfo =
      {
      {"MESSAGE", "String", ""},
      {"X", "int", ""},
      {"Y", "int", ""},
      };
    return pinfo;
  }

  //static initializer for setting look & feel
  static
  {
    try
    {
      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }
    catch(Exception e)
    {
    }
  }
}
