home *** CD-ROM | disk | FTP | other *** search
/ Internet 53 / INTERNET53.iso / pc / software / windows / multimed / real5 / clickandplayapplet.java next >
Encoding:
Java Source  |  1998-03-24  |  4.4 KB  |  161 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // ClickAndPlayApplet.java
  3. //
  4. // Extremely simple java applet sample that uses the high level RAPlayer native 
  5. // method class.
  6. //
  7. // Copyright (c) 1996 by Progressive Networks, Inc.
  8. // All Rights Reserved.
  9. // 
  10. // 
  11. import java.awt.*;
  12. import java.applet.*;
  13. import netscape.javascript.JSException;
  14. import netscape.javascript.JSObject;
  15. import RAObserver;
  16. import RAPlayer;
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. //
  20. //      Class:
  21. //
  22. //              ClickAndPlayApplet 
  23. //
  24. //      Purpose:
  25. //
  26. //              Variation on Scribble Applet. Implements an extremely simple 
  27. //        Java applet that demonstrates the use of the RAPlayer object.
  28. //        Extends the applet class demonstrating the use of the RealAudio 
  29. //        native method in Netscape.
  30. //
  31. public class ClickAndPlayApplet extends Applet{
  32.     int lastx = 0;
  33.     int lasty = 0;
  34.     static boolean firstTime;
  35.  
  36.         public void init() {
  37.         firstTime=true;
  38.     }
  39.  
  40.     public boolean mouseMove(Event e, int x, int y){
  41.     
  42.            if (firstTime) {
  43.         firstTime=false;
  44.         System.out.println("FirstTime! " + firstTime);
  45.         JSObject win = JSObject.getWindow(this);    
  46.             JSObject doc = (JSObject) win.getMember("document");    
  47.  
  48.         RAPlayer ra = (RAPlayer)doc.getMember("javaPlug1");
  49.         ra.DoPlayPause();
  50.         lastx=x;
  51.         lasty=y;
  52.  
  53.         }
  54.         return true;
  55.     }
  56.  
  57.         /////////////////////////////////////////////////////////////////////////////
  58.         //
  59.         //      Method:
  60.         //
  61.         //              ClickAndPlayApplet.mouseDown()
  62.         //
  63.         //      Purpose:
  64.         //
  65.         //              Store x, y mouse position.  Begin playing RealAudio file.
  66.         //
  67.         //      Parameters:
  68.         //
  69.         //              Event e
  70.         //              Java event.
  71.         //
  72.         //              int x
  73.         //              x coordinate of mouse position.
  74.     //
  75.         //              int y
  76.         //              y coordinate of mouse position.
  77.         //
  78.         //      Return Value:
  79.         //
  80.         //              Boolean.
  81.         //
  82.     public boolean mouseDown(Event e, int x, int y){
  83.            JSObject win = JSObject.getWindow(this);    
  84.             JSObject doc = (JSObject) win.getMember("document");    
  85.  
  86.         RAPlayer ra = (RAPlayer)doc.getMember("javaPlug1");
  87.         ra.DoPlayPause();
  88.         lastx=x;
  89.         lasty=y;
  90.         return true;
  91.     }
  92.  
  93.         /////////////////////////////////////////////////////////////////////////////
  94.         //
  95.         //      Method:
  96.         //
  97.         //              ClickAndPlayApplet.mouseUp()
  98.         //
  99.         //      Purpose:
  100.         //
  101.         //              Store x, y mouse position.  Pause RealAudio file.
  102.         //
  103.         //      Parameters:
  104.         //
  105.         //              Event e
  106.         //              Java event.
  107.         //
  108.         //              int x
  109.         //              x coordinate of mouse position.
  110.     //
  111.         //              int y
  112.         //              y coordinate of mouse position.
  113.         //
  114.         //      Return Value:
  115.         //
  116.         //              Boolean.
  117.         //
  118.     public boolean mouseUp(Event e, int x, int y){
  119.            JSObject win = JSObject.getWindow(this);    
  120.             JSObject doc = (JSObject) win.getMember("document");    
  121.  
  122.         RAPlayer ra = (RAPlayer)doc.getMember("javaPlug1");
  123.         ra.DoPlayPause();
  124.         return true;
  125.     }
  126.  
  127.         /////////////////////////////////////////////////////////////////////////////
  128.         //
  129.         //      Method:
  130.         //
  131.         //              ClickAndPlayApplet.mouseDrag()
  132.         //
  133.         //      Purpose:
  134.         //
  135.         //              Draw line from old mouse position to new mouse position.
  136.         //
  137.         //      Parameters:
  138.         //
  139.         //              Event e
  140.         //              Java event.
  141.         //
  142.         //              int newx
  143.         //              new x coordinate of mouse position.
  144.     //
  145.         //              int newy
  146.         //              new y coordinate of mouse position.
  147.         //
  148.         //      Return Value:
  149.         //
  150.         //              Boolean.
  151.         //
  152.  
  153.     public boolean mouseDrag(Event e, int newx, int newy){
  154.         Graphics g=getGraphics();
  155.         g.drawLine(lastx, lasty, newx, newy);
  156.         lastx=newx;
  157.         lasty=newy;
  158.         return true;
  159.     }
  160. }
  161.