// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Skrabble.java

import java.applet.Applet;
import java.awt.*;
import java.net.URL;

public class Skrabble extends Applet
{

    public boolean action(Event event, Object obj)
    {
        if(event.target == b || event.target == tf1)
        {
            String s = tf1.getText().trim();
            if(s.length() > 15)
                s = s.substring(0, 15);
            if(!s.equals("") && port > 0)
            {
                connecting = true;
                tf1.setEditable(false);
                tf1.disable();
                b.disable();
                String s1;
                if(app)
                {
                    tf2.setEditable(false);
                    tf2.disable();
                    tf3.setEditable(false);
                    tf3.disable();
                    s1 = tf2.getText();
                    try
                    {
                        port = Integer.parseInt(tf3.getText());
                    }
                    catch(Exception _ex) { }
                } else
                {
                    s1 = getCodeBase().getHost();
                }
                setStatus(_German.CONNECTING_TO + s1);
                con = new Connection(this, s1, s, port);
            }
            return true;
        } else
        {
            return false;
        }
    }

    void connectionFailure(String s)
    {
        setStatus(s);
        if(app)
        {
            tf2.setEditable(true);
            tf2.enable();
            tf3.setEditable(true);
            tf3.enable();
        }
        tf1.setEditable(true);
        tf1.enable();
        b.enable();
        connecting = false;
        tf1.requestFocus();
    }

    void connectionSuccess(Connection connection)
    {
        setStatus(_German.CONNECTION_ESTABLISHED);
    }

    public void destroy()
    {
        if(con != null)
        {
            con.close();
            con = null;
        }
    }

    public String getAppletInfo()
    {
        return _German.APPLET_INFO;
    }

    public Dimension getMinimumSize()
    {
        return psize;
    }

    public Dimension getPreferredSize()
    {
        return psize;
    }

    public boolean handleEvent(Event event)
    {
        if(!connecting && (event.target instanceof TextField))
        {
            boolean flag = true;
            if(tf1.getText().trim().equals(""))
                flag = false;
            if(app)
            {
                if(tf2.getText().trim().equals(""))
                    flag = false;
                int i = -1;
                try
                {
                    i = Integer.parseInt(tf3.getText());
                }
                catch(Exception _ex) { }
                if(i <= 0 || i >= 65535)
                    flag = false;
            }
            if(flag)
                b.enable();
            else
                b.disable();
        }
        return super.handleEvent(event);
    }

    public void init()
    {
        if(!app)
        {
            String s = getParameter("PORT");
            try
            {
                port = Integer.parseInt(s);
            }
            catch(Exception _ex) { }
            showStatus(_German.LOADING_GRAPHICS);
        }
        Const.mt = new MediaTracker(this);
        GameFrame.staticInit(this);
        TableFrame.staticInit(this);
        try
        {
            Const.mt.waitForAll();
        }
        catch(Exception _ex) { }
        if(!app)
            showStatus("ok!");
        System.gc();
        w = size().width;
        h = size().height;
        setLayout(null);
        Panel panel = new Panel();
        if(app)
        {
            panel.reshape(0, 0, w, h);
            panel.setLayout(new GridLayout(3, 1, 0, 0));
        } else
        {
            panel.reshape(1, 1, w - 2, h - 2);
            panel.setLayout(new GridLayout(2, 1, 0, 0));
        }
        if(app)
        {
            Panel panel1 = new Panel();
            panel1.setLayout(new FlowLayout(0, 10, 5));
            panel1.add(new Z(new Label(_German.SERVER), 75, 25));
            tf2 = new TextField("localhost", 18);
            tf2.setBackground(Color.white);
            panel1.add(tf2);
            panel1.add(new Label(_German.PORT, 0));
            tf3 = new TextField("13279");
            tf3.setBackground(Color.white);
            panel1.add(tf3);
            panel1.setBackground(darkBlue);
            panel.add(panel1);
        }
        Panel panel2 = new Panel();
        panel2.setLayout(new FlowLayout(0, 10, 5));
        panel2.add(new Z(new Label(_German.YOUR_NAME), 75, 25));
        tf1 = new TextField(18);
        tf1.setBackground(Color.white);
        panel2.add(tf1);
        b = new Button(_German.CONNECT);
        b.setBackground(Color.lightGray);
        panel2.add(b);
        panel2.setBackground(darkBlue);
        panel.add(panel2);
        stat = new Label();
        stat.setBackground(lightBlue);
        panel.add(stat);
        setStatus(_German.STATUS_EMPTY);
        add(panel);
        tf1.requestFocus();
        System.gc();
    }

    public static void main(String args[])
    {
        new ZApp(_German.GAME_NAME);
    }

    public void paint(Graphics g)
    {
        g.setColor(frameColor);
        g.drawRect(0, 0, w - 1, h - 1);
    }

    void setStatus(String s)
    {
        stat.setText("   " + s);
    }

    public Skrabble()
    {
        port = 13279;
        app = false;
        connecting = false;
    }

    static Color lightBlue = new Color(200, 210, 255);
    static Color darkBlue = new Color(230, 235, 255);
    static Color frameColor = new Color(90, 90, 192);
    TextField tf1;
    TextField tf2;
    TextField tf3;
    Button b;
    Label stat;
    GameFrame gamef;
    TableFrame tablef;
    Connection con;
    String status;
    int w;
    int h;
    int port;
    boolean app;
    boolean connecting;
    static int stripe;
    static Dimension psize;

    static 
    {
        stripe = 35;
        psize = new Dimension(430, 3 * stripe);
    }
}
