home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / WDESAMPL.BIN / SoundPlayerClass.java < prev    next >
Text File  |  1998-02-26  |  6KB  |  195 lines

  1. /*
  2.     A basic extension of the java.awt.Frame class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. import symantec.itools.multimedia.*;
  8. import symantec.itools.util.Timer;
  9. import symantec.itools.awt.*;
  10. import symantec.itools.awt.ImageButton;
  11. import symantec.itools.multimedia.SoundPlayer;
  12. import symantec.itools.multimedia.ImageViewer;
  13. public class SoundPlayerClass extends Frame
  14. {
  15.     public SoundPlayerClass()
  16.     {
  17.         // This code is automatically generated by Visual Cafe when you add
  18.         // components to the visual environment. It instantiates and initializes
  19.         // the components. To modify the code, only use code syntax that matches
  20.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  21.         // parse your Java file into its visual environment.
  22.         //{{INIT_CONTROLS
  23.         setLayout(null);
  24.         setVisible(false);
  25.         setSize(430,270);
  26.         setBackground(new Color(12632256));
  27.         soundPlayer1 = new symantec.itools.multimedia.SoundPlayer();
  28.         try {
  29.             java.net.URL[] tempURL = new java.net.URL[5];
  30.             tempURL[0] = symantec.itools.net.RelativeURL.getURL("sounds/T1.au");
  31.             tempURL[1] = symantec.itools.net.RelativeURL.getURL("sounds/T2.au");
  32.             tempURL[2] = symantec.itools.net.RelativeURL.getURL("sounds/T3.au");
  33.             tempURL[3] = symantec.itools.net.RelativeURL.getURL("sounds/T4.au");
  34.             tempURL[4] = symantec.itools.net.RelativeURL.getURL("sounds/T5.au");
  35.             soundPlayer1.setURLList(tempURL);
  36.         }
  37.         catch (java.net.MalformedURLException error) { }
  38.         catch(java.beans.PropertyVetoException e) { }
  39.         //$$ soundPlayer1.move(212,61);
  40.         imageViewer1 = new symantec.itools.multimedia.ImageViewer();
  41.         try {
  42.             imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/right.gif"));
  43.         }
  44.         catch (java.net.MalformedURLException error) { }
  45.         catch(java.beans.PropertyVetoException e) { }
  46.         imageViewer1.setBounds(42,7,136,131);
  47.         add(imageViewer1);
  48.         imageViewer2 = new symantec.itools.multimedia.ImageViewer();
  49.         try {
  50.             imageViewer2.setImageURL(symantec.itools.net.RelativeURL.getURL("images/right.gif"));
  51.         }
  52.         catch (java.net.MalformedURLException error) { }
  53.         catch(java.beans.PropertyVetoException e) { }
  54.         imageViewer2.setBounds(251,7,136,131);
  55.         add(imageViewer2);
  56.         imageButton1 = new symantec.itools.awt.ImageButton();
  57.         try {
  58.             imageButton1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/stop.gif"));
  59.         }
  60.         catch (java.net.MalformedURLException error) { }
  61.         catch(java.beans.PropertyVetoException e) { }
  62.         imageButton1.setBounds(136,145,57,58);
  63.         add(imageButton1);
  64.         imageButton2 = new symantec.itools.awt.ImageButton();
  65.         try {
  66.             imageButton2.setImageURL(symantec.itools.net.RelativeURL.getURL("images/play.gif"));
  67.         }
  68.         catch (java.net.MalformedURLException error) { }
  69.         catch(java.beans.PropertyVetoException e) { }
  70.         imageButton2.setBounds(240,145,57,58);
  71.         add(imageButton2);
  72.         setTitle("Sound Player");
  73.         //}}
  74.  
  75.         //{{INIT_MENUS
  76.         //}}
  77.  
  78.         //{{REGISTER_LISTENERS
  79.         SymWindow aSymWindow = new SymWindow();
  80.         this.addWindowListener(aSymWindow);
  81.         SymComponent aSymComponent = new SymComponent();
  82.         SymAction lSymAction = new SymAction();
  83.         imageButton1.addActionListener(lSymAction);
  84.         imageButton2.addActionListener(lSymAction);
  85.         //}}
  86.     }
  87.  
  88.     public SoundPlayerClass(String title)
  89.     {
  90.         this();
  91.         setTitle(title);
  92.     }
  93.  
  94.     public synchronized void show()
  95.     {
  96.         move(50, 50);
  97.         super.show();
  98.     }
  99.  
  100.     public void addNotify()
  101.     {
  102.         // Record the size of the window prior to calling parents addNotify.
  103.         Dimension d = getSize();
  104.         
  105.         super.addNotify();
  106.  
  107.         if (fComponentsAdjusted)
  108.             return;
  109.  
  110.         // Adjust components according to the insets
  111.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  112.         Component components[] = getComponents();
  113.         for (int i = 0; i < components.length; i++)
  114.         {
  115.             Point p = components[i].getLocation();
  116.             p.translate(insets().left, insets().top);
  117.             components[i].setLocation(p);
  118.         }
  119.         fComponentsAdjusted = true;
  120.     }
  121.  
  122.     // Used for addNotify check.
  123.     boolean fComponentsAdjusted = false;
  124.  
  125.     //{{DECLARE_CONTROLS
  126.     symantec.itools.multimedia.SoundPlayer soundPlayer1;
  127.     symantec.itools.multimedia.ImageViewer imageViewer1;
  128.     symantec.itools.multimedia.ImageViewer imageViewer2;
  129.     symantec.itools.awt.ImageButton imageButton1;
  130.     symantec.itools.awt.ImageButton imageButton2;
  131.     //}}
  132.  
  133.     //{{DECLARE_MENUS
  134.     //}}
  135.  
  136.     class SymWindow extends java.awt.event.WindowAdapter
  137.     {
  138.         public void windowClosing(java.awt.event.WindowEvent event)
  139.         {
  140.             Object object = event.getSource();
  141.             if (object == SoundPlayerClass.this)
  142.                 Frame1_WindowClosing(event);
  143.         }
  144.     }
  145.     
  146.     void Frame1_WindowClosing(java.awt.event.WindowEvent event)
  147.     {
  148.         hide();         // hide the Frame
  149.     }
  150.  
  151.     class SymComponent extends java.awt.event.ComponentAdapter
  152.     {
  153.         public void componentHidden(java.awt.event.ComponentEvent event)
  154.         {
  155.             Object object = event.getSource();
  156.         }
  157.     }
  158.  
  159.     class SymAction implements java.awt.event.ActionListener
  160.     {
  161.         public void actionPerformed(java.awt.event.ActionEvent event)
  162.         {
  163.             Object object = event.getSource();
  164.             if (object == imageButton1)
  165.                 imageButton1_actionPerformed(event);
  166.             else if (object == imageButton2)
  167.                 imageButton2_actionPerformed(event);
  168.         }
  169.     }
  170.  
  171.     void imageButton1_actionPerformed(java.awt.event.ActionEvent event)
  172.     {
  173.         // to do: code goes here.
  174.              
  175.         //{{CONNECTION
  176.         // Stop the sound player
  177.         {
  178.             soundPlayer1.stop();
  179.         }
  180.         //}}
  181.     }
  182.  
  183.     void imageButton2_actionPerformed(java.awt.event.ActionEvent event)
  184.     {
  185.         // to do: code goes here.
  186.              
  187.         //{{CONNECTION
  188.         // Start the sound player
  189.         {
  190.             soundPlayer1.play();
  191.         }
  192.         //}}
  193.     }
  194. }
  195.