package yi.net;
/*
	A basic extension of the java.applet.Applet class
 */
import yi.net.*;
import java.awt.*;
import java.applet.*;
import java.net.*;
import netscape.javascript.*;

public class CommApplet extends Applet
{
	public void init()
	{
		// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
		symantec.itools.lang.Context.setApplet(this);

		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setSize(200,150);
		button1.setLabel("using HTMLOutputStream");
		add(button1);
		button1.setBackground(java.awt.Color.lightGray);
		button1.setBounds(12,12,160,24);
		button2.setLabel("using ShowHTML");
		add(button2);
		button2.setBackground(java.awt.Color.lightGray);
		button2.setBounds(12,48,160,24);
		button3.setLabel("call js function");
		add(button3);
		button3.setBackground(java.awt.Color.lightGray);
		button3.setBounds(12,84,160,24);

		//}}

		//{{REGISTER_LISTENERS
		SymMouse aSymMouse = new SymMouse();
		button1.addMouseListener(aSymMouse);
		button2.addMouseListener(aSymMouse);
		button3.addMouseListener(aSymMouse);
		//}}
	}

	//{{DECLARE_CONTROLS
	java.awt.Button button1 = new java.awt.Button();
	java.awt.Button button2 = new java.awt.Button();
	java.awt.Button button3 = new java.awt.Button();
	//}}

	class SymMouse extends java.awt.event.MouseAdapter
	{
		public void mousePressed(java.awt.event.MouseEvent event)
		{
			Object object = event.getSource();
			if (object == button1)
				button1_MousePressed(event);
	        if (object == button2)
				button2_MousePressed(event);
			if (object == button3)
				button3_MousePressed(event);
		}
	}

	void button1_MousePressed(java.awt.event.MouseEvent event)
	{
	    /*
        // Get main browser window from the applet with JSObject.getWindow().
        JSObject main_window = JSObject.getWindow(this);
        // Use JSObject.eval() to create a new window.
        JSObject window = (JSObject)
            main_window.eval("self.open(''," +
                             "'HTMLOutputStream"  + "'," +
                             "'menubar,status,resizable,scrollbars," +
                             "width=" + 400 + ",height=" + 400 + "')");
        // Use JSObject.getMember() to get the document of this new window.
        JSObject document = (JSObject) window.getMember("document");
        // Then use JSObject.call() to open this document.
        document.call("open", null);

        Object[] args= new Object[1];
        args[0]="asfasdfsa";
        document.call("write",args);
        args[0]="<h3>asfasdfssdfdsfdsfsdfsda</h3>";
        document.call("write",args);
        args[0]="<li><a href=\"http://bird.cs.wasghinton.edu/sdf/image1.jpg\">image1</a></li>";
        document.call("write",args);
        document.call("close", null);
        */


        HTMLOutputStream out= new HTMLOutputStream(this, 400,400);
        out.write("asfasdf");
        out.write("<li><a href=\"http://bird.cs.wasghinton.edu/sdf/image1.jpg\">image1</a></li>");
        out.write("<li><a href=\"http://bird.cs.wasghinton.edu/sdf/image2.jpg\">image2</a></li>");
        out.close();

    }

   	void button2_MousePressed(java.awt.event.MouseEvent event)
	{
        String text = "dffd";
        String frame = "";
        String html = "<HEAD>" +
                    "<TITLE>Generated HTML</TITLE>" +
                    "</HEAD>" +
                    "<BODY BGCOLOR=WHITE>" +
                    "<H1>Generated HTML</H1>" +
                    "<H2>Your input:</H2>" +
                    "<XMP>" + text + "</XMP>" +
                    "<H2>Result:</H2>" +
                    text +
                    "</BODY>";
        //if (frame.length() == 0)
        if (true)
            ShowHTML.showPage(this, html);
        else
            ShowHTML.showPage(this, html, frame);
    }

    void button3_MousePressed(java.awt.event.MouseEvent event)
	{
	    JSObject window = JSObject.getWindow(this); // this=applet

	    String[] message = { "An alert message" };
	    //window.call("alert", message);

	    String[] message1 = { "01" };
	    window.call("addImage",message1);
	    String[] message2 = { "02" };
	    window.call("addImage",message2);
	    window.call("displayImages",null);
    }

}
