import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Plan3 extends Applet
implements ActionListener, ItemListener
{
  private Button deal, save;
  private Label label1, label2, textfield;
  private TextField amount,t1,t2;
  private int amount1,amount2,amount3;
  private int number1;
  private Image image,j;
  private int y=0;
  private int y1=0;
  private int y2=0;
  private int no1,no2,no3;
  private int label3,lose;
  private boolean clicked=false;
  private int win,win1,my;
  private int i=5000;
  private AudioClip bird;
  private Checkbox bold, italic;
 

  public void init()
  {
   setLayout(null);

   deal = new Button("Deal");
   add(deal);
   deal.addActionListener(this);
   deal.setBounds(450,370,60,30);

   label1 = new Label("Please enter amount you want to bet :");
   add(label1);
   label1.setBounds(350,330,190,20);

   amount = new TextField(5);
   add(amount);
   amount.setBounds(560,330,50,20);

   textfield = new Label("Your number is :");
   add(textfield);
   textfield.setBounds(350,290,190,20);

   t1 = new TextField(1);
   add(t1);
   t1.setBounds(560,290,50,20);

   image = getImage(getDocumentBase(),"sarah_michelle_gellar2_800.jpg");
   bird = getAudioClip(getDocumentBase(),"tiptoe.au");
   j = getImage(getDocumentBase(),"E&S.jpg");


  t2= new TextField("Bet Your Lucky Number (E&S Product)");
  t2.setFont(new Font("Serif",Font.PLAIN,20));
  add(t2);
  t2.setBounds(40,10,400,30);

  bold = new Checkbox("Bold");
  bold.addItemListener(this);
  add(bold);
  bold.setBounds(440,10,50,30);

  italic = new Checkbox("Italic");
  italic.addItemListener(this);
  add(italic);
  italic.setBounds(500,10,50,30);
  }

  public void itemStateChanged(ItemEvent event)
  {
   int valBold =
   ( bold.getState() ? Font.BOLD : Font.PLAIN);
  
   int valItalic =
   ( italic.getState() ? Font.ITALIC : Font.PLAIN);
    
   t2.setFont(new Font("Serif",valBold + valItalic, 20));
  }

  public void paint(Graphics g)
  {
    g.drawRect(20,60,400,200);
    g.drawLine(120,60,120,260);
    g.drawLine(320,60,320,260);
    g.drawLine(20,160,420,160);
    g.drawLine(220,160,220,260);
    g.setColor(Color.magenta);
    g.fillRect(20,60,100,100);
    g.fillRect(320,60,100,100);
    g.setColor(Color.red);
    g.fillRect(120,160,100,100);
    g.fillRect(320,160,100,100);
    g.setColor(Color.green);
    g.fillRect(20,160,100,100);
    g.fillRect(220,160,100,100);
    g.setColor(Color.black);
    g.drawLine(70,90,70,130);
    g.drawLine(65,95,70,90);
    g.drawLine(60,130,80,130);

    g.drawLine(60,190,80,190);
    g.drawLine(80,190,80,210);
    g.drawLine(80,210,60,210);
    g.drawLine(60,210,60,230);
    g.drawLine(60,230,80,230);

    g.drawLine(160,190,180,190);
    g.drawLine(180,190,180,230);
    g.drawLine(160,210,180,210);
    g.drawLine(160,230,180,230);

    g.drawLine(260,190,260,210);
    g.drawLine(260,210,280,210);
    g.drawLine(280,190,280,230);

    g.drawLine(360,190,380,190);
    g.drawLine(360,190,360,210);
    g.drawLine(360,210,380,210);
    g.drawLine(380,210,380,230);
    g.drawLine(380,230,360,230);

    g.drawLine(360,90,360,130);
    g.drawLine(360,130,380,130);
    g.drawLine(380,130,380,110);
    g.drawLine(380,110,360,110);
    g.drawLine(360,90,380,90);

    g.drawRect(190,90,20,20);
    g.drawRect(210,90,20,20);
    g.drawRect(230,90,20,20);

    g.drawString("Amount of betting $ " +amount1,50,300);

    
    no1 = (int)(Math.random()*6)+1;
    no2 = (int)(Math.random()*6)+1;
    no3 = (int)(Math.random()*6)+1;


    switch(y)
    {
     case 1:g.drawString(""+no1,200,105);break;
    
    }

    switch(y1)
    {
     case 1:g.drawString(""+no2,220,105);break;
    }

    switch(y2)
    {
      case 1:g.drawString(""+no3,240,105);break;
    }
    if(clicked)
    {
    if((no1==my)&&(no2==my)||(no1==my)&&(no3==my)||(no2==my)&&(no3==my))
    {
    g.drawString("You Win :"+win,50,370);
    i=i+win;
    bird.play();
    }
    else if((no1==my)||(no2==my)||(no3==my))
    {
    g.drawString("You Win :"+label3,50,370);
    i=i+label3;
    bird.play();
    }
    else if((no1==my)&&(no2==my)&&(no3==my))
    {
    g.drawString("You Win :"+win1,50,370);
    i=i+win1;
    bird.play();
    }
    else
    {
    g.drawString("Sorry You Lose :"+lose,50,370);
    i=i-lose;
   
    }
   }
   g.drawString("Your Current Accounts Are :" +i,50,350);
   boolean b = g.drawImage(image,450,60,230,230,this);
   g.drawImage(j,80,390,50,90,this);
   g.drawString("Copyright Protected :P",140,435);
  }


   public void actionPerformed(ActionEvent event)
   {
    amount1 = Integer.parseInt(amount.getText());
    amount2 = Integer.parseInt(amount.getText());
    amount3 = Integer.parseInt(amount.getText());
    my = Integer.parseInt(t1.getText());
    label3 =  amount1;
    lose =  amount1;
    win = amount2*2;
    win1 = amount3*3;

   if(event.getSource()==deal)
   {
    y=1;
    y1=1;
    y2=1;
    
    
   }
    clicked=true;
    repaint();
  }
 }
   

