Java2DemoApplet.java
Upload User: cdlibang
Upload Date: 2016-07-17
Package Size: 774k
Code Size: 7k
Category:

2D Graphic

Development Platform:

Java

  1. /*
  2.  * @(#)Java2DemoApplet.java 1.12 99/04/23
  3.  *
  4.  * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  * 
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  * 
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30. import java.awt.*;
  31. import javax.swing.*;
  32. /**
  33.  * A demo that shows Java2D features. 
  34.  *
  35.  * Parameters that can be used in the Java2Demo.html file inside
  36.  * the applet tag to customize demo runs :
  37.               <param name="runs" value="10">
  38.               <param name="delay" value="10">
  39.               <param name="ccthread" value=" ">
  40.               <param name="screen" value="5">
  41.               <param name="antialias" value="true">
  42.               <param name="rendering" value="true">
  43.               <param name="texture" value="true">
  44.               <param name="composite" value="true">
  45.               <param name="verbose" value=" ">
  46.               <param name="buffers" value="3,10">
  47.               <param name="verbose" value=" ">
  48.               <param name="zoom" value=" ">
  49.  *
  50.  * @version @(#)Java2DemoApplet.java 1.12 99/04/23
  51.  * @author Brian Lichtenwalter  (Framework, Intro, demos)
  52.  * @author Jim Graham           (demos)
  53.  */
  54. public class Java2DemoApplet extends JApplet {
  55.     public static JApplet applet;
  56.     public void init() {
  57.         applet = this;
  58.         JPanel panel = new JPanel();
  59.         getContentPane().add(panel,BorderLayout.CENTER);
  60.         panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
  61.         JPanel progressPanel = new JPanel() {
  62.             public Insets getInsets() {
  63.                 return new Insets(40,30,20,30);
  64.             }
  65.         };
  66.         progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
  67.         panel.add(Box.createGlue());
  68.         panel.add(progressPanel);
  69.         panel.add(Box.createGlue());
  70.         progressPanel.add(Box.createGlue());
  71.         Dimension d = new Dimension(400, 20);
  72.         Java2Demo.progressLabel = new JLabel("Loading, please wait...");
  73.         Java2Demo.progressLabel.setMaximumSize(d);
  74.         progressPanel.add(Java2Demo.progressLabel);
  75.         progressPanel.add(Box.createRigidArea(new Dimension(1,20)));
  76.         Java2Demo.progressBar = new JProgressBar();
  77.         Java2Demo.progressBar.setStringPainted(true);
  78.         Java2Demo.progressLabel.setLabelFor(Java2Demo.progressBar);
  79.         Java2Demo.progressBar.setAlignmentX(CENTER_ALIGNMENT);
  80.         Java2Demo.progressBar.setMaximumSize(d);
  81.         Java2Demo.progressBar.setMinimum(0);
  82.         Java2Demo.progressBar.setValue(0);
  83.         progressPanel.add(Java2Demo.progressBar);
  84.         progressPanel.add(Box.createGlue());
  85.         progressPanel.add(Box.createGlue());
  86.         Rectangle ab = getContentPane().getBounds();
  87.         panel.setPreferredSize(new Dimension(ab.width,ab.height));
  88.         getContentPane().add(panel,BorderLayout.CENTER);
  89.         validate();
  90.         setVisible(true);
  91.         Java2Demo.demo = new Java2Demo();
  92.         getContentPane().remove(panel);
  93.         getContentPane().setLayout(new BorderLayout());
  94.         getContentPane().add(Java2Demo.demo, BorderLayout.CENTER);
  95.         String param = null;
  96.         if ((param = getParameter("delay")) != null) {
  97.             RunWindow.delay = Integer.parseInt(param);
  98.         } 
  99.         if (getParameter("ccthread") != null) {
  100.             Java2Demo.demo.ccthreadCB.setSelected(true);
  101.         }
  102.         if ((param = getParameter("screen")) != null) {
  103.             Java2Demo.demo.controls.screenCombo.setSelectedIndex(Integer.parseInt(param));
  104.         } 
  105.         if ((param = getParameter("antialias")) != null) {
  106.             Java2Demo.demo.controls.aliasCB.setSelected(param.endsWith("true"));
  107.         } 
  108.         if ((param = getParameter("rendering")) != null) {
  109.             Java2Demo.demo.controls.renderCB.setSelected(param.endsWith("true"));
  110.         } 
  111.         if ((param = getParameter("texture")) != null) {
  112.             Java2Demo.demo.controls.textureCB.setSelected(param.endsWith("true"));
  113.         } 
  114.         if ((param = getParameter("composite")) != null) {
  115.             Java2Demo.demo.controls.compositeCB.setSelected(param.endsWith("true"));
  116.         } 
  117.         if (getParameter("verbose") != null) {
  118.             Java2Demo.demo.verboseCB.setSelected(true);
  119.         } 
  120.         if ((param = getParameter("columns")) != null) {
  121.             DemoGroup.columns = Integer.parseInt(param);
  122.         } 
  123.         if ((param = getParameter("buffers")) != null) {
  124.             // usage -buffers=3,10
  125.             RunWindow.buffersFlag = true;
  126.             int i = param.indexOf(',');
  127.             String s1 = param.substring(0, i);
  128.             RunWindow.bufBeg = Integer.parseInt(s1);
  129.             s1 = param.substring(i+1, param.length());
  130.             RunWindow.bufEnd = Integer.parseInt(s1);
  131.         } 
  132.         if (getParameter("zoom") != null) {
  133.             RunWindow.zoomCB.setSelected(true);
  134.         }
  135.         if ((param = getParameter("runs")) != null) {
  136.             RunWindow.numRuns = Integer.parseInt(param);
  137.             Java2Demo.demo.createRunWindow();
  138.             RunWindow.runB.doClick();
  139.         } 
  140.         validate();
  141.         repaint();
  142.         Java2Demo.demo.requestDefaultFocus();
  143.     }
  144.     public void start() {
  145.         Java2Demo.demo.start();
  146.     }
  147.     public void stop() {
  148.         Java2Demo.demo.stop();
  149.     }
  150. }