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.  
  3. // ClickAndPlayApplet.java
  4.  
  5. //
  6.  
  7. // Extremely simple java applet sample that uses the high level RAPlayer native 
  8.  
  9. // method class.
  10.  
  11. //
  12.  
  13. // Copyright (c) 1996 by Progressive Networks, Inc.
  14.  
  15. // All Rights Reserved.
  16.  
  17. // 
  18.  
  19. // 
  20.  
  21. import java.awt.*;
  22.  
  23. import java.applet.*;
  24.  
  25. import netscape.javascript.JSException;
  26.  
  27. import netscape.javascript.JSObject;
  28.  
  29. import RAObserver;
  30.  
  31. import RAPlayer;
  32.  
  33.  
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36.  
  37. //
  38.  
  39. //      Class:
  40.  
  41. //
  42.  
  43. //              ClickAndPlayApplet 
  44.  
  45. //
  46.  
  47. //      Purpose:
  48.  
  49. //
  50.  
  51. //              Variation on Scribble Applet. Implements an extremely simple 
  52.  
  53. //        Java applet that demonstrates the use of the RAPlayer object.
  54.  
  55. //        Extends the applet class demonstrating the use of the RealAudio 
  56.  
  57. //        native method in Netscape.
  58.  
  59. //
  60.  
  61. public class ClickAndPlayApplet extends Applet{
  62.  
  63.     int lastx = 0;
  64.  
  65.     int lasty = 0;
  66.  
  67.     static boolean firstTime;
  68.  
  69.  
  70.  
  71.         public void init() {
  72.  
  73.         firstTime=true;
  74.  
  75.     }
  76.  
  77.  
  78.  
  79.     public boolean mouseMove(Event e, int x, int y){
  80.  
  81.     
  82.  
  83.            if (firstTime) {
  84.  
  85.         firstTime=false;
  86.  
  87.         System.out.println("FirstTime! " + firstTime);
  88.  
  89.         JSObject win = JSObject.getWindow(this);    
  90.  
  91.             JSObject doc = (JSObject) win.getMember("document");    
  92.  
  93.  
  94.  
  95.         RAPlayer ra = (RAPlayer)doc.getMember("javaPlug1");
  96.  
  97.         ra.DoPlayPause();
  98.  
  99.         lastx=x;
  100.  
  101.         lasty=y;
  102.  
  103.  
  104.  
  105.         }
  106.  
  107.         return true;
  108.  
  109.     }
  110.  
  111.  
  112.  
  113.         /////////////////////////////////////////////////////////////////////////////
  114.  
  115.         //
  116.  
  117.         //      Method:
  118.  
  119.         //
  120.  
  121.         //              ClickAndPlayApplet.mouseDown()
  122.  
  123.         //
  124.  
  125.         //      Purpose:
  126.  
  127.         //
  128.  
  129.         //              Store x, y mouse position.  Begin playing RealAudio file.
  130.  
  131.         //
  132.  
  133.         //      Parameters:
  134.  
  135.         //
  136.  
  137.         //              Event e
  138.  
  139.         //              Java event.
  140.  
  141.         //
  142.  
  143.         //              int x
  144.  
  145.         //              x coordinate of mouse position.
  146.  
  147.     //
  148.  
  149.         //              int y
  150.  
  151.         //              y coordinate of mouse position.
  152.  
  153.         //
  154.  
  155.         //      Return Value:
  156.  
  157.         //
  158.  
  159.         //              Boolean.
  160.  
  161.         //
  162.  
  163.     public boolean mouseDown(Event e, int x, int y){
  164.  
  165.            JSObject win = JSObject.getWindow(this);    
  166.  
  167.             JSObject doc = (JSObject) win.getMember("document");    
  168.  
  169.  
  170.  
  171.         RAPlayer ra = (RAPlayer)doc.getMember("javaPlug1");
  172.  
  173.         ra.DoPlayPause();
  174.  
  175.         lastx=x;
  176.  
  177.         lasty=y;
  178.  
  179.         return true;
  180.  
  181.     }
  182.  
  183.  
  184.  
  185.         /////////////////////////////////////////////////////////////////////////////
  186.  
  187.         //
  188.  
  189.         //      Method:
  190.  
  191.         //
  192.  
  193.         //              ClickAndPlayApplet.mouseUp()
  194.  
  195.         //
  196.  
  197.         //      Purpose:
  198.  
  199.         //
  200.  
  201.         //              Store x, y mouse position.  Pause RealAudio file.
  202.  
  203.         //
  204.  
  205.         //      Parameters:
  206.  
  207.         //
  208.  
  209.         //              Event e
  210.  
  211.         //              Java event.
  212.  
  213.         //
  214.  
  215.         //              int x
  216.  
  217.         //              x coordinate of mouse position.
  218.  
  219.     //
  220.  
  221.         //              int y
  222.  
  223.         //              y coordinate of mouse position.
  224.  
  225.         //
  226.  
  227.         //      Return Value:
  228.  
  229.         //
  230.  
  231.         //              Boolean.
  232.  
  233.         //
  234.  
  235.     public boolean mouseUp(Event e, int x, int y){
  236.  
  237.            JSObject win = JSObject.getWindow(this);    
  238.  
  239.             JSObject doc = (JSObject) win.getMember("document");    
  240.  
  241.  
  242.  
  243.         RAPlayer ra = (RAPlayer)doc.getMember("javaPlug1");
  244.  
  245.         ra.DoPlayPause();
  246.  
  247.         return true;
  248.  
  249.     }
  250.  
  251.  
  252.  
  253.         /////////////////////////////////////////////////////////////////////////////
  254.  
  255.         //
  256.  
  257.         //      Method:
  258.  
  259.         //
  260.  
  261.         //              ClickAndPlayApplet.mouseDrag()
  262.  
  263.         //
  264.  
  265.         //      Purpose:
  266.  
  267.         //
  268.  
  269.         //              Draw line from old mouse position to new mouse position.
  270.  
  271.         //
  272.  
  273.         //      Parameters:
  274.  
  275.         //
  276.  
  277.         //              Event e
  278.  
  279.         //              Java event.
  280.  
  281.         //
  282.  
  283.         //              int newx
  284.  
  285.         //              new x coordinate of mouse position.
  286.  
  287.     //
  288.  
  289.         //              int newy
  290.  
  291.         //              new y coordinate of mouse position.
  292.  
  293.         //
  294.  
  295.         //      Return Value:
  296.  
  297.         //
  298.  
  299.         //              Boolean.
  300.  
  301.         //
  302.  
  303.  
  304.  
  305.     public boolean mouseDrag(Event e, int newx, int newy){
  306.  
  307.         Graphics g=getGraphics();
  308.  
  309.         g.drawLine(lastx, lasty, newx, newy);
  310.  
  311.         lastx=newx;
  312.  
  313.         lasty=newy;
  314.  
  315.         return true;
  316.  
  317.     }
  318.  
  319. }
  320.  
  321.