home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / DirectX / dplay / DpChatApplet.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  3.9 KB  |  142 lines

  1. // 
  2. //  (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4. //  File:               DpChatApplet.java
  5. //  Description:        Allows DPChat to be run from an applet
  6. //
  7.  
  8. import java.applet.*;
  9. import java.awt.*;
  10. import com.ms.ui.*;
  11. import com.ms.com.*;
  12. import com.ms.directX.*;
  13. import DpChat;
  14.  
  15. public class DpChatApplet extends Applet implements Runnable
  16. {
  17.  
  18.     private    DpChat    m_dpc;
  19.     private Thread    m_dpcThread = null;
  20.  
  21.     //=-------------------------------------------------------------------------
  22.     // DpChatApplet Class Constructor
  23.     //=-------------------------------------------------------------------------
  24.     public DpChatApplet()
  25.     {    
  26.     }
  27.  
  28.     //=--------------------------------------------------------------------------
  29.     // getAppletInfo
  30.     //=--------------------------------------------------------------------------
  31.     //    The getAppletInfo() method returns a string describing the applet's
  32.     // author, copyright date, or miscellaneous information.
  33.     
  34.     public String getAppletInfo()
  35.     {
  36.         return "Name: DpChatApplet\r\n";
  37.     }
  38.  
  39.  
  40.     
  41.     //=-------------------------------------------------------------------------
  42.     // init
  43.     //=--------------------------------------------------------------------------
  44.     // The init() method is called by the AWT when an applet is first loaded or
  45.     // reloaded.  Override this method to perform whatever initialization your
  46.     // applet needs, such as initializing data structures, loading images or
  47.     // fonts, creating frame windows, setting the layout manager, or adding UI
  48.     // components.
  49.     public void init()
  50.     {       
  51.         //close down our prev instance if we 
  52.         //are being reloaded
  53.         CloseDPC();
  54.     }
  55.  
  56.     //=-------------------------------------------------------------------------
  57.     // destroy
  58.     //=--------------------------------------------------------------------------
  59.     // Place additional applet clean up code here.  destroy() is called when
  60.     // when you applet is terminating and being unloaded.
  61.     public void destroy()
  62.     {
  63.         //cleanup code in stop
  64.     }
  65.     
  66.     //=-------------------------------------------------------------------------
  67.     // paint
  68.     //=--------------------------------------------------------------------------    
  69.     public void paint(Graphics g)
  70.     {
  71.         g.drawString("Direct Play Chat for Java", 10, 15);
  72.     }
  73.     
  74.     
  75.     //= -------------------------------------------------------------------------
  76.     // start
  77.     //=--------------------------------------------------------------------------    
  78.     // The start() method is called when the page containing the applet
  79.     // first appears on the screen. The AppletWizard's initial implementation
  80.     // of this method starts execution of the applet's thread.
  81.     public void start()
  82.     {
  83.         if (m_dpcThread== null)
  84.         {
  85.             m_dpcThread= new Thread(this);
  86.             m_dpcThread.start();
  87.         }
  88.     }
  89.     
  90.     //=-------------------------------------------------------------------------
  91.     // stop
  92.     //=--------------------------------------------------------------------------    
  93.     // called when browser is terminated
  94.     public void stop()
  95.     {
  96.         CloseDPC();
  97.     }
  98.  
  99.  
  100.     //=-------------------------------------------------------------------------
  101.     // run
  102.     //=--------------------------------------------------------------------------    
  103.     // called from start
  104.     //
  105.     public void run()
  106.     {
  107.         try {
  108.             m_dpc = new DpChat();
  109.             add(m_dpc);        
  110.             m_dpc.setBounds(0,30,550,430);
  111.             m_dpc.setVisible(true);    
  112.             m_dpc.show();
  113.             m_dpc.DoChat();    
  114.         }
  115.         catch (Exception e){
  116.             //do nothing
  117.         }
  118.     }
  119.  
  120.     //=-------------------------------------------------------------------------
  121.     // closeDPC 
  122.     //=--------------------------------------------------------------------------    
  123.     // if dpchat class exits
  124.     // close it down
  125.     //
  126.     void CloseDPC(){
  127.         if (m_dpc!=null){
  128.             m_dpc.StopAll();
  129.             m_dpc.DoCloseAll();
  130.         }
  131.  
  132.         if (m_dpcThread!=null)
  133.             m_dpcThread.stop();
  134.  
  135.         m_dpcThread=null;
  136.         m_dpc=null;
  137.         System.gc();
  138.     }
  139.  
  140.  
  141. }
  142.