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

  1. package Jcd; // -- Listing-1 -- Player.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.*;                                //  8
  9.                                              //  9
  10. public class Player                          // 10
  11.   extends Form 
  12.   implements ActionListener { // Main window.
  13.                                              // 11
  14.   SmartDrive cdPlayer; // Hardware interface // 12
  15.   Program program;     // Program tracks to play.
  16.                                              // 14
  17.   Display  display;    // Numeric display    // 15
  18.   Controls controls;   // Push buttons       // 16  
  19.                                              // 17
  20.                        // File-Menu items    // 18
  21.   private MenuItem fileProgramItem  = 
  22.              new MenuItem("Program");        // 19
  23.   private MenuItem fileExitItem     = 
  24.              new MenuItem("Exit");           // 20
  25.                                              // 21
  26.   //                                         // 22
  27.   // 1. Connect to a cdrom device.           // 23
  28.   // 2. Create the interface:                // 24
  29.   //     the display-panel;                  // 25
  30.   //     the control-panel;                  // 26
  31.   // 3. Establish the panel components as    // 27
  32.   //    clients of the monitor.              // 28
  33.                                              // 29
  34.   public static void main(String[] args)     // 30
  35.   {                                          // 31
  36.     Player player =                          // 32
  37.       new Player();  // Create a GUI CD player 
  38.   }                                          // 33
  39.                                              // 34
  40.   public Player()                            // 35
  41.   {                                          // 36
  42.     super("Jcd");                            // 37
  43.                     // Init CDROM hardware   // 38
  44.     String device = "/dev/cdrom";            // 39
  45.     String module = 
  46.       "native/ix86-Linux/Jcd_Drive.so";      // 40
  47.     int flags     = 0;                       // 41
  48.                                              // 42
  49.     cdPlayer= new SmartDrive(device,module,flags); 
  50.                     // Init GUI              // 44
  51.     setResizable(true);                      // 45
  52.     setMenuBar(new MenuBar());               // 46
  53.     getMenuBar().add(createFileMenu());      // 47
  54.     display  = new Display(cdPlayer);        // 48
  55.     controls = new Controls(cdPlayer);       // 49
  56.     addCenter(display);                      // 50
  57.     addCenter(controls);                     // 51
  58.                   // Handle close requests.
  59.     addWindowListener(new DoClose());        // 52
  60.     pack();       // Resize to fit.          // 53
  61.     show();       // Let the user have it!   // 54
  62.                   // Now everyone is ready...// 55
  63.                   // ...start processing events
  64.     cdPlayer.monitor.start();                // 56
  65.   }                                          // 57
  66.                                              // 58
  67.   public void actionPerformed(ActionEvent event)  
  68.   {                                          // 60
  69.     Object source = event.getSource();       // 61
  70.     if (source == fileProgramItem) {         // 62
  71.       if (program == null || !program.isShowing())
  72.         program = new Program(cdPlayer);     // 64
  73.     }                                        // 65
  74.     else if (source == fileExitItem)         // 66
  75.       System.exit(0);                        // 67
  76.   }                                          // 68
  77.                                              // 69
  78.   private Menu createFileMenu()              // 70
  79.   {                                          // 71
  80.     Menu fileMenu = new Menu("File");        // 72
  81.     fileMenu.add(fileProgramItem);           // 73
  82.     fileMenu.addSeparator();                 // 74
  83.     fileMenu.add(fileExitItem);              // 75
  84.     fileProgramItem.addActionListener(this); // 76
  85.     fileExitItem.addActionListener(this);    // 77
  86.     return fileMenu;                         // 78
  87.   }                                          // 79
  88.                                              // 80
  89.   private class DoClose extends WindowAdapter {
  90.     public void windowClosing(WindowEvent e) {
  91.       System.exit(0);                        // 83
  92.     }                                        // 84
  93.   }                                          // 85
  94. }                                            // 86
  95.