home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / WDESAMPL.BIN / CardTest.java < prev    next >
Text File  |  1996-12-06  |  4KB  |  113 lines

  1. /*
  2.  * @(#)CardTest.java    1.3 96/12/06
  3.  *
  4.  * Copyright (c) 1994-1996 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.  
  31. import java.awt.*;
  32. import java.applet.Applet;
  33.  
  34. class CardPanel extends Panel {
  35.     Panel create(LayoutManager layout) {
  36.     Panel p = new Panel();
  37.     p.setLayout(layout);
  38.     p.add("North",   new Button("one"));
  39.     p.add("West",   new Button("two"));
  40.     p.add("South",  new Button("three"));
  41.     p.add("East",   new Button("four"));
  42.     p.add("Center", new Button("five"));
  43.     return p;
  44.     }
  45.  
  46.     CardPanel() {
  47.     setLayout(new CardLayout());
  48.     add("one", create(new FlowLayout()));
  49.     add("two", create(new BorderLayout()));
  50.     add("three", create(new GridLayout(2, 2)));
  51.     add("four", create(new BorderLayout(10, 10)));
  52.     add("five", create(new FlowLayout(FlowLayout.LEFT, 10, 10)));
  53.     add("six", create(new GridLayout(2, 2, 10, 10)));
  54.     }
  55.  
  56.     public Dimension preferredSize() {
  57.     return new Dimension(200, 100);
  58.     }
  59. }
  60.  
  61. public class CardTest extends Applet {
  62.     CardPanel cards;
  63.  
  64.     public CardTest() {
  65.     setLayout(new BorderLayout());
  66.     add("Center", cards = new CardPanel());
  67.     Panel p = new Panel();
  68.     p.setLayout(new FlowLayout());
  69.     add("South", p);
  70.     p.add(new Button("first"));
  71.     p.add(new Button("next"));
  72.     p.add(new Button("previous"));
  73.     p.add(new Button("last"));
  74.     Choice c = new Choice();
  75.     c.addItem("one");
  76.     c.addItem("two");
  77.     c.addItem("three");
  78.     c.addItem("four");
  79.     c.addItem("five");
  80.     p.add(c);
  81.     }
  82.  
  83.     public boolean action(Event evt, Object arg) {
  84.     if (evt.target instanceof Choice) {
  85.         ((CardLayout)cards.getLayout()).show(cards,(String)arg);
  86.     } else {
  87.         if ("first".equals(arg)) {
  88.         ((CardLayout)cards.getLayout()).first(cards);
  89.         } else if ("next".equals(arg)) {
  90.         ((CardLayout)cards.getLayout()).next(cards);
  91.         } else if ("previous".equals(arg)) {
  92.         ((CardLayout)cards.getLayout()).previous(cards);
  93.         } else if ("last".equals(arg)) {
  94.         ((CardLayout)cards.getLayout()).last(cards);
  95.         } else {
  96.         ((CardLayout)cards.getLayout()).show(cards,(String)arg);
  97.         }
  98.     }
  99.     return true;
  100.     }
  101.  
  102.     public static void main(String args[]) {
  103.     Frame f = new Frame("CardTest");
  104.     CardTest cardTest = new CardTest();
  105.     cardTest.init();
  106.     cardTest.start();
  107.  
  108.     f.add("Center", cardTest);
  109.     f.resize(300, 300);
  110.     f.show();
  111.     }
  112. }
  113.