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

  1. // 
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4. import java.awt.*;
  5. import java.awt.peer.ComponentPeer;
  6. import java.applet.*;
  7. import com.ms.com.*;
  8. import com.ms.awt.*;
  9. import com.ms.awt.peer.*;
  10. import com.ms.directX.*;
  11.  
  12. public class FlipCube extends Applet implements Runnable, DirectXConstants
  13. {
  14.     boolean    running = true;
  15.     Thread t; 
  16.     FlipCubeCanvas cube;
  17.  
  18.     ////////////////////////////////////////////////////////////////////////////
  19.  
  20.     public static void main(String args[])
  21.     {
  22.         FlipCubeFrame frame = new FlipCubeFrame("Direct3D Imediate Mode Sample");
  23.  
  24.         frame.setResizable(false);
  25.         frame.show();
  26.         frame.hide();
  27.  
  28.         frame.resize(frame.insets().left + frame.insets().right  + 256,
  29.                      frame.insets().top  + frame.insets().bottom + 256);
  30.  
  31.  
  32.         FlipCube applet = new FlipCube();
  33.         frame.add("Center", applet);
  34.  
  35.         frame.show();
  36.         applet.init();
  37.         applet.start();
  38.     }
  39.  
  40.     //////////////////////////////////////////////////////////////////////////
  41.     //
  42.     // init
  43.     //
  44.     public void init()
  45.     {
  46.         BorderLayout bl = new BorderLayout();
  47.         setLayout(bl);
  48.  
  49.         cube = new FlipCubeCanvas();
  50.         add("Center",cube);
  51.  
  52.         show();
  53.  
  54.         Dimension d = bl.preferredLayoutSize(this);
  55.         resize(d.width, d.height);
  56.     }
  57.  
  58.     public void start()
  59.     {
  60.         try 
  61.         {
  62.             cube.InitDDraw();
  63.             cube.InitD3D();
  64.             cube.InitExecuteBuffer();
  65.         } 
  66.         catch(Exception e) 
  67.         {
  68.             System.out.println("Direct3D Initialization Exception:"+e);
  69.         }
  70.  
  71.         requestFocus();
  72.  
  73.         t = new Thread(this);
  74.         running = true;
  75.         t.start();
  76.     }
  77.  
  78.     public void stop()
  79.     {
  80.         running = false;
  81.         t.stop();
  82.     }
  83.  
  84.     //////////////////////////////////////////////////////////////////////////
  85.     public void run()
  86.     {
  87.         while (running)
  88.             cube.updateframe();
  89.  
  90.         cube.BackgroundMaterial    = null;
  91.         cube.D3DView            = null;
  92.         cube.D3DExBuf            = null;
  93.         cube.D3DDevice            = null;
  94.         cube.D3D                = null;
  95.         cube.DDPal                = null;            
  96.         cube.DDClipper            = null;        
  97.         cube.DDSPrimary            = null;        
  98.         cube.DDSOffscreen        = null;    
  99.         cube.DD                    = null;                
  100.  
  101.         System.gc();
  102.     }
  103. }
  104.