

import java.io.*;
import java.net.*;
import java.applet.*;
import java.awt.*;

public class SQLClient extends Applet
{
	static final int MYPORT = 6700;
	String instring = "No string yet", outstring = "Nothing yet";
        Button b;
        TextArea t;
        List l;


	public void init()
	{
		
                setLayout(new GridLayout(5, 1));
                b = new Button("Click to execute query");
                t = new TextArea(20, 40);
                l = new List();
                add(new Label("Enter your query here..."));
                add(t);
                add(b);
                add(new Label ("and peruse your results here"));
                add(l);
                resize(800, 800);

	}

	void run_socket()
	{
		Socket s = null;
		try
		{
			s = new Socket(getCodeBase().getHost(), MYPORT);
			DataInputStream sinstream = new 
				DataInputStream(s.getInputStream());
			PrintStream soutstream = new 
				PrintStream(s.getOutputStream());

                        soutstream.println(t.getText());
                        l.clear();
			outstring = sinstream.readLine();
                        while (outstring != null)
                        {
                                l.addItem(outstring);
                                outstring = sinstream.readLine();
                        }
			
			
		}
		catch (IOException e) 
			{System.err.println(e);}
		finally{
			try{ if (s != null) s.close();}
			catch (IOException e) {}
		}
	}
	public boolean action (Event e, Object o)
	{
		if (e.target instanceof Button)
		{
			run_socket();
			return true;
		}
		else 
		{
			return false;
		}
	}
}
