home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / javasdk / sdk-java.exe / SDKJava.cab / Samples / directX / d3drm / Viewer / TestGraph.java < prev    next >
Encoding:
Java Source  |  1996-10-10  |  2.9 KB  |  131 lines

  1. import java.awt.*;
  2. import java.awt.peer.ComponentPeer;
  3. import java.applet.*;
  4. import com.ms.com.*;
  5. import com.ms.awt.*;
  6. import com.ms.awt.peer.*;
  7. import com.ms.directX.*;
  8. import java.net.URL;
  9. import java.net.MalformedURLException;
  10. import java.io.FilenameFilter;
  11. import java.io.File;
  12.  
  13. public class TestGraph extends Applet
  14. {
  15.     Stretch         s;
  16.     Button             doIt;
  17.     FlickStretch    f = null;
  18.     FlickViewer        v = null;
  19.     
  20.     public String frameMenu[] = null;
  21.     
  22.     ////////////////////////////////////////////////////////////////////////////
  23.  
  24.     public static void main(String args[])
  25.     {
  26.         TestGraphFrame frame = new TestGraphFrame("DirectX sample");
  27.  
  28.         //----------------------------------------------------------------------
  29.         // Must show Frame before we size it so insets() will return valid values
  30.         frame.show();
  31.         frame.hide();
  32.         frame.resize(frame.insets().left + frame.insets().right  + 128,
  33.                      frame.insets().top  + frame.insets().bottom + 64);
  34.  
  35.         TestGraph applet = new TestGraph();
  36.  
  37.         frame.add("Center", applet);
  38.         applet.init();
  39.         applet.start();
  40.         applet.frameMenu = frame.frameMenu;
  41.         frame.show();
  42.     }
  43.  
  44.     //////////////////////////////////////////////////////////////////////////
  45.     //
  46.     // init
  47.     //
  48.     public void init()
  49.     {
  50.         doIt = new Button("Start Viewer");
  51.         s    = new Stretch(this);
  52.         
  53.         setLayout(new GridLayout(1, 2, 0, 0));
  54.         Panel pnButtons = new Panel();
  55.         add(s);
  56.         add(pnButtons);
  57.         s.addNotify();
  58.         s.resize(64,64);
  59.         s.show();
  60.         
  61.         pnButtons.setLayout(new GridLayout(2, 1, 0, 0));
  62.         pnButtons.add(doIt);
  63.  
  64.         f = s.doInit();
  65.         if( f != null )
  66.             f.start();
  67.     }
  68.     
  69.     //////////////////////////////////////////////////////////////////////////
  70.     
  71.     public boolean action(Event e, Object arg)
  72.     {
  73.         Object target = e.target;
  74.  
  75.         if( target == doIt )
  76.         {
  77.             f.stop();
  78.             
  79.             ViewFrame vFrame;
  80.         
  81.             vFrame = new ViewFrame("Direct 3D in Java!", this);
  82.  
  83.             vFrame.resize(640, 480);
  84.             vFrame.show();
  85.             v = vFrame.startDirect(this, frameMenu);
  86.             v.start();
  87.             return true;
  88.         }
  89.         
  90.     return false;
  91.     }
  92.     
  93.     //////////////////////////////////////////////////////////////////////////
  94.  
  95.     public String getFileName(String rawFileName)
  96.     {
  97.         String file;
  98.  
  99.         try
  100.         {
  101.             URL url = new URL( getDocumentBase(), rawFileName);
  102.             file = url.getFile();
  103.             char c0 = file.charAt(0);
  104.             char c1 = file.charAt(1);
  105.             char c2 = file.charAt(2);
  106.             if( ((c0 == '/') && (c2 == ':')) || ((c0 == '/') && (c1 == '\\') && (c2 == '\\')) )
  107.             {
  108.                 char ch[] = new char[file.length()-1];
  109.                 file.getChars(1,file.length(),ch,0);
  110.                 for( int i=0; i<ch.length; i++)
  111.                     if( ch[i] == '/' )
  112.                         ch[i] = '\\';
  113.  
  114.                 file = new String(ch);
  115.             }
  116.         }
  117.         catch(MalformedURLException me)
  118.         {
  119.             file = new String(rawFileName);
  120.         }
  121.         catch(NullPointerException me)
  122.         {
  123.             file = new String(rawFileName);
  124.         }
  125.         return file;
  126.     }
  127.  
  128.     //////////////////////////////////////////////////////////////////////////
  129.  
  130. }
  131.