Yurttas/PL/OOL/Java/F/05/02/05/00/NameButton03.java

 1/**
 2 *  Copyright(C) 1998
 3 *  All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4 *
 5 *  Permission to use, copy, modify, and distribute this
 6 *  software and its documentation for EDUCATIONAL purposes
 7 *  and without fee is hereby granted provided that this
 8 *  copyright notice appears in all copies.
 9 *
10 *  @date   : January 1, 1998.
11 *  @authorĀ : Salih Yurttas.
12 */
13
14
15import java.awt.*;
16
17import java.io.*;
18
19import sl.*;
20
21public class NameButton03 extends Frame {
22
23  public static void main(String[] args)
24    throws IOException
25  {
26    Frame f = new NameButton03();
27
28    f.setSize(400, 320);
29    f.show();
30  }
31
32  public NameButton03() 
33    throws IOException
34  {
35    int[] iList = {2,
36                   3,
37                   1,
38                   1};
39    int NP = iList.length;
40
41    setLayout(new GridLayout(NP,1));
42
43    Panel[] pList = new Panel[NP];
44    int NB=0;
45    for(int i=0; i<NP; i++) {
46      NB += iList[i];
47      pList[i] = new Panel(new GridLayout(1,iList[i]));
48    }
49
50    StringList lList = new StringList(NB);
51    lList.getStringList();
52  
53    Button[] bList = new Button[NB];
54    for(int i=0; i<NB; i++)
55      bList[i] = new Button(lList.getStringAt(i)); 
56   
57    int bI=0, 
58        eI=0;
59    for(int i=0; i<NP; i++) {
60      eI += iList[i];
61      makePanel(pList, i, bList, bI, eI);
62      add(pList[i]);
63      bI += iList[i];
64    }
65  }
66
67  public void makePanel(Panel[] pList,
68                        int pIndex,
69                        Button[] bList,
70                        int bBIndex,
71                        int bEIndex) {
72
73    for(int i=bBIndex; i<bEIndex; i++)
74      pList[pIndex].add(bList[i]);
75  }
76
77}