home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / lg / issue29 / HAMILTON / Controls.java next >
Encoding:
Java Source  |  1998-01-24  |  2.7 KB  |  58 lines

  1. package Jcd; // -- Listing-3 -- Controls.java//  1
  2.                                              //  2
  3. import java.io.*;                            //  3
  4. import java.util.*;                          //  4
  5. import java.awt.*;                           //  5
  6. import java.awt.event.*;                     //  6
  7.                                              //  7
  8. import Jcd.SmartDrive;                       //  8
  9. import Jcd.Monitor;                          //  9
  10.                                              // 10
  11. class Controls                               // 11 
  12.   extends Panel 
  13.   implements ActionListener {             
  14.                                              // 12
  15.   // Control panel, buttons: play, stop, eject ...
  16.                                              // 14
  17.   private SmartDrive cdPlayer;               // 15
  18.                                              // 16
  19.   private Button play  = new Button("Play"); // 17
  20.   private Button pause = new Button("Pause");// 18
  21.   private Button stop  = new Button("Stop"); // 19
  22.   private Button next  = new Button("Next"); // 20
  23.   private Button prev  = new Button("Prev"); // 21
  24.   private Button eject = new Button("Eject");// 22
  25.                                              // 23
  26.   public Controls(SmartDrive drive)          // 24
  27.   {                                          // 25
  28.     cdPlayer = drive;                        // 26
  29.     setLayout(new GridLayout(1, 6, 2, 2));   // 27
  30.     add(play); add(stop); add(pause);        // 28
  31.     add(prev); add(next); add(eject);
  32.   }                                          // 29
  33.                                              // 30
  34.   private void add(Button b) {               // 31
  35.     b.addActionListener(this);               // 32
  36.     super.add(b);                            // 33
  37.   }                                          // 34
  38.                                              // 35
  39.   public void actionPerformed(ActionEvent event) {
  40.     try {                                    // 37
  41.       Object source = event.getSource();     // 38
  42.                                              // 39
  43.       if (source == play) cdPlayer.startPlaying(); 
  44.       else if (source == stop)  cdPlayer.stop();
  45.       else if (source == next)  cdPlayer.next();
  46.       else if (source == prev)  cdPlayer.prev();
  47.       else if (source == pause) 
  48.         cdPlayer.togglePause();
  49.       else if (source == eject) cdPlayer.eject();
  50.     }                                        // 45
  51.     catch (DriveException except) {          // 46
  52.       System.out.println("Exception " + except); 
  53.     }                                        // 48
  54.   }                                          // 49
  55.                                              // 50
  56. }                                            // 51
  57.                                              // 52
  58.