home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / msdev / samples / sun / cardtest / cardtest.java < prev    next >
Text File  |  1996-07-10  |  4KB  |  114 lines

  1. /*
  2.  * @(#)CardTest.java    1.7 95/08/23 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  8.  * without fee is hereby granted. 
  9.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  10.  * for further important copyright and trademark information and to
  11.  * http://java.sun.com/licensing.html for further important licensing
  12.  * information for the Java (tm) Technology.
  13.  * 
  14.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  18.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20.  * 
  21.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  22.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  23.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  24.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  25.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  26.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  27.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  28.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  29.  * HIGH RISK ACTIVITIES.
  30.  */
  31.  
  32. import java.awt.*;
  33. import java.applet.Applet;
  34.  
  35. class CardPanel extends Panel {
  36.     Panel create(LayoutManager layout) {
  37.     Panel p = new Panel();
  38.     p.setLayout(layout);
  39.     p.add("North",  new Button("one"));
  40.     p.add("West",   new Button("two"));
  41.     p.add("South",  new Button("three"));
  42.     p.add("East",   new Button("four"));
  43.     p.add("Center", new Button("five"));
  44.     return p;
  45.     }
  46.  
  47.     CardPanel() {
  48.     setLayout(new CardLayout());
  49.     add("one", create(new FlowLayout()));
  50.     add("two", create(new BorderLayout()));
  51.     add("three", create(new GridLayout(2, 2)));
  52.     add("four", create(new BorderLayout(10, 10)));
  53.     add("five", create(new FlowLayout(FlowLayout.LEFT, 10, 10)));
  54.     add("six", create(new GridLayout(2, 2, 10, 10)));
  55.     }
  56.  
  57.     public Dimension preferredSize() {
  58.     return new Dimension(200, 100);
  59.     }
  60. }
  61.  
  62. public class cardtest extends Applet {
  63.     CardPanel cards;
  64.  
  65.     public cardtest() {
  66.     setLayout(new BorderLayout());
  67.     add("Center", cards = new CardPanel());
  68.     Panel p = new Panel();
  69.     p.setLayout(new FlowLayout());
  70.     add("South", p);
  71.     p.add(new Button("first"));
  72.     p.add(new Button("next"));
  73.     p.add(new Button("previous"));
  74.     p.add(new Button("last"));
  75.     Choice c = new Choice();
  76.     c.addItem("one");
  77.     c.addItem("two");
  78.     c.addItem("three");
  79.     c.addItem("four");
  80.     c.addItem("five");
  81.     p.add(c);
  82.     }
  83.  
  84.     public boolean action(Event evt, Object arg) {
  85.     if (evt.target instanceof Choice) {
  86.         ((CardLayout)cards.getLayout()).show(cards,(String)arg);
  87.     } else {
  88.         if ("first".equals(arg)) {
  89.         ((CardLayout)cards.getLayout()).first(cards);
  90.         } else if ("next".equals(arg)) {
  91.         ((CardLayout)cards.getLayout()).next(cards);
  92.         } else if ("previous".equals(arg)) {
  93.         ((CardLayout)cards.getLayout()).previous(cards);
  94.         } else if ("last".equals(arg)) {
  95.         ((CardLayout)cards.getLayout()).last(cards);
  96.         } else {
  97.         ((CardLayout)cards.getLayout()).show(cards,(String)arg);
  98.         }
  99.     }
  100.     return true;
  101.     }
  102.  
  103.     public static void main(String args[]) {
  104.     Frame f = new Frame("CardTest");
  105.     cardtest cardTest = new cardtest();
  106.     cardTest.init();
  107.     cardTest.start();
  108.  
  109.     f.add("Center", cardTest);
  110.     f.resize(300, 300);
  111.     f.show();
  112.     }
  113. }
  114.