home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / AppB / CardTest / CardPanel.class (.txt) next >
Encoding:
Java Class File  |  1996-07-09  |  1.6 KB  |  37 lines

  1. import java.awt.BorderLayout;
  2. import java.awt.Button;
  3. import java.awt.CardLayout;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.FlowLayout;
  7. import java.awt.GridLayout;
  8. import java.awt.LayoutManager;
  9. import java.awt.Panel;
  10.  
  11. class CardPanel extends Panel {
  12.    public Dimension preferredSize() {
  13.       return new Dimension(200, 100);
  14.    }
  15.  
  16.    CardPanel() {
  17.       ((Container)this).setLayout(new CardLayout());
  18.       ((Container)this).add("one", this.create(new FlowLayout()));
  19.       ((Container)this).add("two", this.create(new BorderLayout()));
  20.       ((Container)this).add("three", this.create(new GridLayout(2, 2)));
  21.       ((Container)this).add("four", this.create(new BorderLayout(10, 10)));
  22.       ((Container)this).add("five", this.create(new FlowLayout(0, 10, 10)));
  23.       ((Container)this).add("six", this.create(new GridLayout(2, 2, 10, 10)));
  24.    }
  25.  
  26.    Panel create(LayoutManager layout) {
  27.       Panel p = new Panel();
  28.       ((Container)p).setLayout(layout);
  29.       ((Container)p).add("North", new Button("one"));
  30.       ((Container)p).add("West", new Button("two"));
  31.       ((Container)p).add("South", new Button("three"));
  32.       ((Container)p).add("East", new Button("four"));
  33.       ((Container)p).add("Center", new Button("five"));
  34.       return p;
  35.    }
  36. }
  37.