home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / jgl_1_1.exe / examples / SList1.java < prev    next >
Encoding:
Java Source  |  1996-09-10  |  1.6 KB  |  55 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2.  
  3. import java.util.Enumeration;
  4. import jgl.*;
  5.  
  6. /**
  7.  * Construction, enumeration, access, pushing, popping. 
  8.  * <p>
  9.  * @see jgl.SListist
  10.  * @version 1.1
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class SList1
  15.   {
  16.   public static void main( String[] args )
  17.     {
  18.     SList list = new SList();
  19.     list.pushBack( "bat" );
  20.     list.add( "cat" );
  21.     list.pushFront( "ape" );
  22.     System.out.println( list );
  23.     System.out.println();
  24.  
  25.     System.out.println( "Enumerate the SList" );    
  26.     Enumeration e = list.elements();
  27.     while( e.hasMoreElements() )
  28.       System.out.println( e.nextElement() );
  29.     System.out.println();
  30.  
  31.     System.out.println( "Iterate through the SList" );
  32.     for( SListIterator i = list.begin(); !i.equals( list.end() ); i.advance() )
  33.       System.out.println( i.get() );
  34.     System.out.println();
  35.  
  36.     System.out.println( "Demonstrate access" );
  37.     System.out.println( "list.at( 0 ) = " + list.at( 0 ) );
  38.     System.out.println( "list.front() = " + list.front() );
  39.     System.out.println( "list.at( 2 ) = " + list.at( 2 ) );
  40.     System.out.println( "list.back() = " + list.back() );
  41.     System.out.println();
  42.  
  43.     System.out.println( "Demonstrate modification" );
  44.     list.put( 1, "fox" );
  45.     System.out.println( list );
  46.  
  47.     System.out.println( "popFront() returns: " + list.popFront() );
  48.     System.out.println( "After popFront() = " + list );
  49.  
  50.     System.out.println( "popBack() returns: " + list.popBack() );
  51.     System.out.println( "After popBack() = " + list );
  52.     }
  53.   }
  54.  
  55.