/*
 * File: AWTDemo.java
 * 
 * Date		Author		Changes
 * ----------------------------------------------------------------
 * 10 Mar 1998	M Ravishankar	Created
 */


import java.awt.*;
import java.awt.event.*;


/**
 * This demo creates a simple GUI with a text window and two buttons, to simulate
 * a simple speech recognition application.
 * 
 * Clicking on one button toggles its label between "Start Recording" and
 * "Stop Recording".  The other button is labelled "Clear", but it doesn't do anything.
**/


/**
 * Class for handling ActionEvents (i.e., button clicks) on the first button.
 * It merely toggles the buttons title between two strings.
**/
class RecordHandler implements ActionListener {
  // Implement the actionPerformed() method declared in the ActionListener interface.
  public void actionPerformed(ActionEvent e) {
    // Get the button object that caused this event
    Button b = (Button)e.getSource();
    
    // Check its current label and switch it
    if ((b.getLabel()).equals("Start Recording")) {
      b.setLabel("Stop Recording");
      
      // Presumably do other stuff here, like actually starting the recording
    } else {
      b.setLabel("Start Recording");
      
      // Presumably do other stuff here, like actually stopping the recording, then
      // performing automatic speech recognition on the recorded audio and inserting
      // the text in the text window of the application.
    }
  }
}


// The main application class
//
public class AWTDemo {
  public static void main (String[] args) {
    // Create a frame (the top level window) for the GUI.  It is initially invisible.
    Frame f = new Frame("Big Frame");

    // Create a panel as a container for the two buttons.
    Panel p = new Panel();

    // Create a text area of some default size.  The application does nothing with
    // this area, but you can actually type in here.
    TextArea t = new TextArea(5, 40);

    // Create the two buttons.  The clear button does not do anything, but it is
    // intended to clear the text area.
    Button b1 = new Button ("Start Recording");
    Button b2 = new Button ("Clear");
    
    // Create a handler object for handling button clicks on the Record button
    // and bind it to the button.
    b1.addActionListener (new RecordHandler());
    
    // Insert the various objects into their containers.  Note that each container
    // has its own default layout manager.  The frame f has a BorderLayout manager.
    // The panel p has a FlowLayout manager.  Use the appropriate add() method for
    // the associated layout manager.
    p.add (b1);		// Add buttons to panel (left to right)
    p.add (b2);
    f.add ("North", p);	// Add panel and text area to top level frame.
    f.add ("South", t);

    f.setResizable(true);

    // Actually layout all the subcomponents at their sizes.
    f.pack ();
    
    // Show the frame.  Note that the main program does not exit until the window
    // has been destroyed.
    f.show ();
  }
}
