HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"What AWT Version Do You Use"
Volume: 3 Issue: 10, p. 16

	

Listing 1: The CompTree class.
 
// CompTree.java 

package java.awt; 

public class CompTree { 

public static void printTree(Container c) { 
   // Prints the component tree, whose top is c 
   printInfo(c, 0); 
   printTree(c, 4); 
} 

private static void printTree(Container c, int l) { 
   // Gets the component list of the c container 
   Component a[] = c.getComponents(); 
   if (a == null) return; 
   // Prints the information about each component 
   for (int i = 0; i < a.length; i++) { 
      printInfo(a[i], l); 
      if (a[i] instanceof Container) 
         printTree((Container) a[i], l+4); 
   } 
} 

private static void printInfo(Component c, int l) { 
   // This string computing is not optimized 
   String s = new String(); 
   for (int i = 0; i < l; i++) 
      s += ' '; 
   // Prints the information about the c component 
   System.out.print(s); 
   System.out.print(c.getClass().getName()); 
   System.out.print(" -- "); 
   System.out.print(c.getName()); 
   if (c instanceof Container) { 
      LayoutManager m = ((Container) c).getLayout(); 
      System.out.print(" ("); 
      if (m != null) 
         System.out.print(m.getClass().getName()); 
      System.out.print(")"); 
   } 
   System.out.print(" -- "); 
   System.out.print(c.newEventsOnly); 
   System.out.println(); 
   // Uncomment next line for more information 
   // System.out.println(s + "+ " + c); 
} 

} 
  

Listing 2: The component hierarchy of SmartLogin.

SmartLogin -- frame0 (java.awt.GridLayout) -- true 
    java.awt.Label -- label0 -- false 
    java.awt.TextField -- textfield0 -- false 
    java.awt.Panel -- panel0 (java.awt.GridLayout) 
                                          -- false 
        java.awt.Checkbox -- checkbox0 -- false 
        java.awt.Checkbox -- checkbox1 -- false 
        java.awt.Checkbox -- checkbox2 -- false 
    java.awt.Label -- label1 -- false 
    java.awt.TextField -- textfield1 -- false 
    java.awt.Panel -- panel1 (java.awt.FlowLayout) 
                                          -- false 
        java.awt.Button -- button0 -- true 
        java.awt.Button -- button1 -- true 


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.