import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/** DemoHighLevelEvents - demo of high-level events.<p>
*
* This is a follow-on program to <code>DemoLowLevelEvents</code>.  The
* behaviour is identical, however the approach
* is much better because we use <i>high-level</i>,
* or <i>semantic</i>, events.<p>
*
* We add just one listener to the beep button, an action listener:<p>
*
* <pre>
*     beep.addActionListener(this);
* </pre>
*
* An action event fires whenever the button is pressed.  This occurs
* when the button is clicked on via the mouse pointer or when the
* ALT_B keystroke is detected.  (The <code>setMnemonic</code> method
* is used, as in <code>DemoLowLevelEvents</code>.)
* <p>
*
* Screen snap ...<p>
* <center><img src="DemoHighLevelEvents-1.gif"></center><p>
*
* @see <a href="DemoHighLevelEvents.java">source code</a>
* @author Scott MacKenzie, 2003
*/
public class DemoHighLevelEvents
{
   public static void main(String[] args)
   {
      DemoHighLevelEventsFrame frame = new DemoHighLevelEventsFrame();
      frame.setTitle("DemoHighLevelEvents");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.show();
   }
}

// -----------------------------
// define the application window
// -----------------------------

class DemoHighLevelEventsFrame extends JFrame implements ActionListener 
{
   // -----------------------------------------------------------------
   // declare variables and components accessed by more than one method
   // -----------------------------------------------------------------

   private JButton beep;

   // -----------
   // constructor
   // -----------

   public DemoHighLevelEventsFrame()
   {
      // -------------------------------
      // create and configure components
      // -------------------------------

      beep = new JButton("Beep");
      beep.setMnemonic(KeyEvent.VK_B);

      // -------------
      // add listeners
      // -------------

      beep.addActionListener(this);

      // ------------------
      // arrange components
      // ------------------

      // put components in a panel

      JPanel panel = new JPanel();
      panel.add(beep);

      // make the panel this extended JFrame's content pane

      this.setContentPane(panel);
   }

   // -------------------------------
   // implement ActionListener method
   // -------------------------------

   public void actionPerformed(ActionEvent ae)
   {
      //Toolkit.getDefaultToolkit().beep();
		System.out.print("\07"); 
		System.out.flush();
   }
}

