import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*
<APPLET CODE=DoisOuUm.class WIDTH=420 HEIGHT=380></APPLET>
*/

public class DoisOuUm extends Applet implements ActionListener
{
  public TextArea ta;
  public Label legenda1, legenda2, legenda3;
  public TextField caixa1, caixa2, caixa3;
  public Button botao;
  int x, w, y;

  public void init()
  {
      legenda1 = new Label ("Jogador A:\n"); add(legenda1);
      caixa1 = new TextField("1", 3); add (caixa1);
      legenda2 = new Label ("Jogador B:\n"); add(legenda2);
      caixa2 = new TextField("1", 3); add (caixa2);
      legenda3 = new Label ("Jogador C:\n"); add(legenda3);
      caixa3 = new TextField("1", 3); add (caixa3);
      botao = new Button ("Dois ou um");  add(botao); botao.addActionListener(this);
      ta = new TextArea("",16,30); add(ta);
  }

  public void actionPerformed(ActionEvent e)
  {
    x=Integer.valueOf(caixa1.getText()).intValue();
    w=Integer.valueOf(caixa2.getText()).intValue();
    y=Integer.valueOf(caixa3.getText()).intValue();

    if (e.getSource() == botao)
    {
       ta.append ("\n Abrindo o Jogo!");
       ta.append ("\n O jogador A escolheu " + x );
       ta.append ("\n O jogador B escolheu " + w );
       ta.append ("\n O jogador C escolheu " + y );

       if(x==y)
       { // início do bloco
           if(x==w)   ta.append ("\n Houve empate, joguem novamente. \n=========");
           else       ta.append ("\n B foi vencedor.   \n========= ");
       } // final do bloco
       else if (x==w) ta.append ("\n C foi vencedor.   \n=========");
            else      ta.append ("\n A foi o vencedor. \n========= ");
       }
   }
}

