home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / awt / test / cardtest.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.9 KB  |  102 lines

  1. /*
  2.  * @(#)CardTest.java    1.7 95/08/23 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 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 purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. import java.awt.*;
  21. import java.applet.Applet;
  22.  
  23. class CardPanel extends Panel {
  24.     Panel create(LayoutManager layout) {
  25.     Panel p = new Panel();
  26.     p.setLayout(layout);
  27.     p.add("North",   new Button("one"));
  28.     p.add("West",   new Button("two"));
  29.     p.add("South",  new Button("three"));
  30.     p.add("East",   new Button("four"));
  31.     p.add("Center", new Button("five"));
  32.     return p;
  33.     }
  34.  
  35.     CardPanel() {
  36.     setLayout(new CardLayout());
  37.     add("one", create(new FlowLayout()));
  38.     add("two", create(new BorderLayout()));
  39.     add("three", create(new GridLayout(2, 2)));
  40.     add("four", create(new BorderLayout(10, 10)));
  41.     add("five", create(new FlowLayout(FlowLayout.LEFT, 10, 10)));
  42.     add("six", create(new GridLayout(2, 2, 10, 10)));
  43.     }
  44.  
  45.     public Dimension preferredSize() {
  46.     return new Dimension(200, 100);
  47.     }
  48. }
  49.  
  50. public class CardTest extends Applet {
  51.     CardPanel cards;
  52.  
  53.     public CardTest() {
  54.     setLayout(new BorderLayout());
  55.     add("Center", cards = new CardPanel());
  56.     Panel p = new Panel();
  57.     p.setLayout(new FlowLayout());
  58.     add("South", p);
  59.     p.add(new Button("first"));
  60.     p.add(new Button("next"));
  61.     p.add(new Button("previous"));
  62.     p.add(new Button("last"));
  63.     Choice c = new Choice();
  64.     c.addItem("one");
  65.     c.addItem("two");
  66.     c.addItem("three");
  67.     c.addItem("four");
  68.     c.addItem("five");
  69.     p.add(c);
  70.     }
  71.  
  72.     public boolean action(Event evt, Object arg) {
  73.     if (evt.target instanceof Choice) {
  74.         ((CardLayout)cards.getLayout()).show(cards,(String)arg);
  75.     } else {
  76.         if ("first".equals(arg)) {
  77.         ((CardLayout)cards.getLayout()).first(cards);
  78.         } else if ("next".equals(arg)) {
  79.         ((CardLayout)cards.getLayout()).next(cards);
  80.         } else if ("previous".equals(arg)) {
  81.         ((CardLayout)cards.getLayout()).previous(cards);
  82.         } else if ("last".equals(arg)) {
  83.         ((CardLayout)cards.getLayout()).last(cards);
  84.         } else {
  85.         ((CardLayout)cards.getLayout()).show(cards,(String)arg);
  86.         }
  87.     }
  88.     return true;
  89.     }
  90.  
  91.     public static void main(String args[]) {
  92.     Frame f = new Frame("CardTest");
  93.     CardTest cardTest = new CardTest();
  94.     cardTest.init();
  95.     cardTest.start();
  96.  
  97.     f.add("Center", cardTest);
  98.     f.resize(300, 300);
  99.     f.show();
  100.     }
  101. }
  102.