home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Micrsoft / SAMPLES / VJ6SAMPL.EXE / BindPubs / splash / SplashScreen.java < prev    next >
Encoding:
Java Source  |  1998-02-24  |  4.4 KB  |  138 lines

  1.  
  2. /*  Copyright (C) Microsoft Corporation, 1996-1998.  All rights reserved.
  3.  
  4.   This source code is intended only as a supplement to Microsoft
  5.   Visual J++ 6.0.  See this product's on-line documentation for detailed   
  6. information regarding Microsoft code samples.
  7.  
  8. */
  9.  
  10. package splash;
  11. import wfc.ui.*;
  12. import wfc.core.*;
  13. /**Defines a functionless form that lets the user know the application has started
  14.  */
  15. public final class SplashScreen extends Form implements ISplashable
  16. {
  17.     /**takes the form for which it is supposed to open
  18.      */
  19.     public SplashScreen(Form pop)
  20.     {
  21.         //define some reasonable defaults
  22.         initForm();
  23.         //add an event handler to the creating form's onCreate Event (called from the win32 createWindowEx call)
  24.         pop.addOnCreate(popCreate);
  25.         try
  26.         {
  27.             ((ISplashable)pop).initSplash(this);
  28.         }
  29.         //a form needn't implement ISplashable to call this splashScreen
  30.         catch(ClassCastException e)
  31.         {
  32.             //finish the default SplashScreen
  33.             initSplash(this);
  34.         }
  35.         show();
  36.         update();
  37.         bringToFront();
  38.     }
  39.     public void pop_create(Object source, CreateEvent event)
  40.     {
  41.         Form pop = (Form)source;
  42.         dispose();
  43.     }
  44.     //put the default picturebox and label on the class level so they can be accessed by forms using SplashScreen's default implementation
  45.     protected PictureBox splashPicture = new PictureBox();
  46.     protected Label splashLabel = new Label();
  47.     //create an event handler for the parent's create event
  48.     CreateEventHandler popCreate = new CreateEventHandler(this.pop_create);
  49.     Container components = new Container();
  50.  
  51.     private void initForm()
  52.     {
  53.         this.setAnchor(ControlAnchor.NONE);
  54.         this.setBackColor(new Color(255, 240, 240));
  55.         this.setCursor(Cursor.WAIT);
  56.         this.setLocation(new Point(200, 150));
  57.         this.setSize(new Point(406, 295));
  58.         this.setTabIndex(-1);
  59.         this.setTabStop(false);
  60.         this.setText("");
  61.         this.setAutoScaleBaseSize(16);
  62.         this.setBorderStyle(FormBorderStyle.FIXED_TOOLWINDOW);
  63.         this.setClientSize(new Point(404, 293));
  64.         this.setControlBox(false);
  65.         this.setMaxButton(false);
  66.         this.setMinButton(false);
  67.         this.setShowInTaskbar(false);
  68.     }    
  69.     /**Returns a handle to the pictureBox added in the default initSplash
  70.      * must be called after SplashScreen.initSplash(SplashScreen)
  71.      */
  72.     public PictureBox getSplashPicture()
  73.     {
  74.         return splashPicture;
  75.     }
  76.     /**Replaces the pictureBox in the default initSplash with a new one
  77.      * must be called before SplashScreen.initSplash(SplashScreen)
  78.      */
  79.     public void setSplashPicture(PictureBox splashPicture)
  80.     {
  81.         this.splashPicture = splashPicture;
  82.     }
  83.     /**Replaces the picture in the PictureBox with the picture in the path given
  84.      */
  85.     public void setSplashPicture(String imageFilePath) throws wfc.io.IOException
  86.     {
  87.         setSplashPicture(new Bitmap(imageFilePath));
  88.     }
  89.     /**Replaces the picture in the PictureBox with the Image object passed in
  90.      * Resizes the PictureBox and form to accomodate
  91.      */
  92.     public void setSplashPicture(Image image)
  93.     {
  94.         Point size = image.getSize();
  95.         splashPicture.setSize(size);
  96.         setSize(size.x+60, size.y+150);
  97.     }
  98.     /**Returns a handle to the Label added in the default initSplash
  99.      * must be called after SplashScreen.initSplash(SplashScreen)
  100.      */
  101.     public Label getSplashLabel()
  102.     {
  103.         return splashLabel;
  104.     }
  105.     /**replaces the pictureBox in the default initSplash with a new one
  106.      * must be called before SplashScreen.initSplash(SplashScreen)
  107.      */
  108.     public void setSplashLabel(Label splashLabel)
  109.     {
  110.         this.splashLabel = splashLabel;
  111.     }
  112.     public void initSplash(SplashScreen splash)
  113.     {
  114.         PictureBox splashPicture = splash.splashPicture;
  115.         Label splashLabel = splash.splashLabel;
  116.         splashPicture.setLocation(new Point(30, 10));
  117.         splashPicture.setSize(new Point(350, 172));
  118.         splashPicture.setAnchor(ControlAnchor.TOPLEFT);
  119.         try 
  120.         {
  121.             //the Bitmap constructor has to take an absolute pathname, or a path from the folder in which the project is run
  122.             splashPicture.setImage(new Bitmap("SplashScreen.gif"));
  123.         }
  124.         catch(wfc.io.IOException e){}
  125.         splashLabel.setBackColor(Color.WHITE);
  126.         splashLabel.setFont(new Font("MS Sans Serif", -30));
  127.         splashLabel.setForeColor(new Color(128, 0, 128));
  128.         splashLabel.setLocation(new Point(40, 210));
  129.         splashLabel.setAnchor(ControlAnchor.BOTTOM);
  130.         splashLabel.setSize(new Point(340, 40));
  131.         splashLabel.setText("Made with Visual J++ 6.0");
  132.         splashLabel.setTabIndex(2);
  133.         splash.setNewControls(new Control[] {
  134.             splashLabel, 
  135.             splashPicture});
  136.     }
  137. }
  138.