import java.applet.Applet;
import java.awt.* ;
import java.awt.event.* ;

/*
---------------------------------------------------------------------
 NeilW's josie Class
 (c) Neil Whitehouse 2015
---------------------------------------------------------------------
*/
public class josie extends Applet
{
    private jillDisplay jillCanvas  ;  /* Canvas */
    private Image       jillImage   ;  /* Image  */

    private Button    replayButton  ;  /* Button */
    private Button    replayButton1 ;  /* Button */
    private Button    replayButton2 ;  /* Button */
    private TextField replayText    ;  /* Text   */

    public josie ()
    {
      super () ;
    }

    public void init ()
    {
      super.init () ;

      jillImage = getImage (getCodeBase (), "sequazel.png") ;

      jillCanvas      = new jillDisplay (jillImage)      ;
      replayButton    = new Button      ("debug")        ;
      replayButton1   = new Button      ("pour")         ;
      replayButton2   = new Button      ("scroll")       ;
      replayText      = new TextField   ("50", 6)        ;
      Panel jillPanel = new Panel       ()               ;
      Label timeLabel = new Label       ("milliseconds") ;

      replayButton.addActionListener  (jillCanvas) ;
      replayButton1.addActionListener (new josiePourHandler   ()) ;
      replayButton2.addActionListener (new josieScrollHandler ()) ;

      jillPanel.setLayout     (new FlowLayout (FlowLayout.RIGHT, 15, 15)) ;
      jillPanel.setBackground (Color.lightGray) ;
      jillPanel.add           (replayText)      ;
      jillPanel.add           (timeLabel)       ;
      jillPanel.add           (replayButton2)   ;
      jillPanel.add           (replayButton1)   ;
      jillPanel.add           (replayButton)    ;

      setLayout     (new BorderLayout(5, 5)) ;
      setBackground (Color.white)            ;
      add           ("Center", jillCanvas)   ;
      add           ("South",  jillPanel)    ;
      setVisible    (true)                   ;
    }
    /*
    -----------------------------------------------------------------
    Paint
    -----------------------------------------------------------------
    */
    public void paint (Graphics g)
    {
      super.paint (g) ;
    }
    /*
    -----------------------------------------------------------------
    Act on controls
    -----------------------------------------------------------------
    */
    class josiePourHandler implements ActionListener
    {
      public void actionPerformed (ActionEvent evt)
      {
        if (evt.getSource() == replayButton1)
        { String   s1 = new String ("POUR" + replayText.getText()) ;
          AWTEvent e1 = new ActionEvent (this, Event.ACTION_EVENT, s1) ;

          setBackground (Color.blue) ;
          repaint       () ;

          replayButton.dispatchEvent (e1) ;
          jillCanvas.repaint () ;
        }
      }
    }
    class josieScrollHandler implements ActionListener
    {
      public void actionPerformed (ActionEvent evt)
      {
        if (evt.getSource() == replayButton2)
        { String   s1 = new String ("SCRL" + replayText.getText()) ;
          AWTEvent e1 = new ActionEvent (this, Event.ACTION_EVENT, s1) ;

          setBackground (Color.green) ;
          repaint       () ;

          replayButton.dispatchEvent (e1) ;
          jillCanvas.repaint () ;
        }
      }
    }
    /*
    -----------------------------------------------------------------
    Stop
    -----------------------------------------------------------------
    */
    public void stop ()
    {
      super.stop () ;
    }
}

