home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / javafile / ch09 / Dialer.java < prev    next >
Encoding:
Java Source  |  1998-12-14  |  3.8 KB  |  132 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4.  
  5. /*
  6.  * the dialer applet
  7.  */
  8. public class Dialer extends Applet implements ActionListener {
  9.  
  10.  
  11. AudioClip touchTones[] = new AudioClip[12];
  12.  
  13. public Button NumberButton1;
  14. public Button NumberButton2;
  15. public Button NumberButton3;
  16. public Button NumberButton4;
  17. public Button NumberButton5;
  18. public Button NumberButton6;
  19. public Button NumberButton7;
  20. public Button NumberButton8;
  21. public Button NumberButton9;
  22. public Button NumberButton0;
  23. public Button PoundButton;
  24. public Button StarButton; 
  25. /*
  26.  * called when the applet is loaded
  27.  * load audio clips and add the keypad panel
  28.  */
  29. public void init () {
  30.  
  31.     int i;
  32.     String name;
  33.  
  34.     for (i=0; i<10; i+=1) {
  35.         name = "touchtone."+i+".au";
  36.         showStatus ("Getting "+name);
  37.         touchTones[i] = getAudioClip (getCodeBase(), name);
  38.     }
  39.     name = "touchtone.star.au";
  40.     showStatus ("Getting "+name);
  41.     touchTones[10] = getAudioClip (getCodeBase(), name);
  42.  
  43.     name = "touchtone.pound.au";
  44.     showStatus ("Getting "+name);
  45.     touchTones[11] = getAudioClip (getCodeBase(), name);
  46.  
  47.     setLayout(new BorderLayout());
  48.  
  49.     //add ("Center", keypad = new Keypad (touchTones));
  50.  
  51.     //Font    font = new Font ("Times", Font.BOLD, 14);
  52.  
  53.     Color   miscColor = new Color (0, 0, 255);
  54.     //setFont (font);
  55.  
  56.     NumberButton1 =  new Button ("1");
  57.     add ("South",NumberButton1);
  58.     NumberButton2 = new Button ("2");
  59.     add ("South", NumberButton2 );
  60.     NumberButton3 = new Button ("3");
  61.     add ("South", NumberButton3 );
  62.     NumberButton4 = new Button ("4");
  63.     add ("South", NumberButton4);
  64.     NumberButton5 = new Button ("5");
  65.     add ("South", NumberButton5);
  66.     NumberButton6 = new Button ("6");
  67.     add ("South", NumberButton6 );
  68.  
  69.     NumberButton7 = new Button ("7");
  70.     add ("South", NumberButton7);
  71.     NumberButton8 = new Button ("8");
  72.     add ("South", NumberButton8 );
  73.     NumberButton9 = new Button ("9");
  74.     add ("South", NumberButton9 );
  75.  
  76.     PoundButton= new Button ("*");
  77.     add ("South", PoundButton );
  78.     PoundButton.setBackground (miscColor);
  79.  
  80.     NumberButton0 =  new Button ("0");
  81.     add ("South", NumberButton0);
  82.  
  83.     StarButton = new Button ("#");
  84.     add ("South", StarButton);
  85.     StarButton.setBackground (miscColor);
  86.  
  87.     setLayout (new GridLayout (4, 3, 4, 4));
  88.  
  89.     NumberButton1.addActionListener(this);
  90.     NumberButton2.addActionListener(this);
  91.     NumberButton3.addActionListener(this);
  92.     NumberButton4.addActionListener(this);
  93.     NumberButton5.addActionListener(this);
  94.     NumberButton6.addActionListener(this);
  95.     NumberButton7.addActionListener(this);
  96.     NumberButton8.addActionListener(this);
  97.     NumberButton9.addActionListener(this);
  98.     NumberButton0.addActionListener(this);
  99.     PoundButton.addActionListener(this);
  100.     StarButton.addActionListener(this);
  101. }
  102.  
  103. public void actionPerformed (ActionEvent ev)
  104. {
  105.     Object object1 = ev.getSource();
  106.     if (object1 == StarButton)
  107.         touchTones[10].play ();
  108.     else if (object1 == PoundButton)
  109.         touchTones[11].play ();
  110.     else if (object1 == NumberButton0)
  111.         touchTones[0].play ();
  112.     else if (object1 == NumberButton1)
  113.         touchTones[1].play ();
  114.     else if (object1 == NumberButton2)
  115.         touchTones[2].play ();
  116.     else if (object1 == NumberButton3)
  117.         touchTones[3].play ();
  118.     else if (object1 == NumberButton4)
  119.         touchTones[4].play ();
  120.     else if (object1 == NumberButton5)
  121.         touchTones[5].play ();
  122.     else if (object1 ==NumberButton6)
  123.         touchTones[6].play ();
  124.     else if (object1 == NumberButton7)
  125.         touchTones[7].play ();
  126.     else if (object1 ==NumberButton8)
  127.         touchTones[8].play ();
  128.     else if (object1 == NumberButton9)
  129.         touchTones[9].play ();
  130. }
  131. }
  132.