
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.applet.AppletContext;

public class internetsitesiseciciSW extends JApplet {
   private Hashtable internetsitesi;
   private Vector siteIsimleri;

   public void init()
   {
      internetsitesi = new Hashtable();
      siteIsimleri = new Vector();

      getinternetsitesiFromHTMLParameters();

      Container c = getContentPane();
      c.add( new JLabel( "Internet internetsitesi seciniz : " ),
             BorderLayout.NORTH );

      final JList siteChooser = new JList( siteIsimleri );
      siteChooser.addListSelectionListener(
         new ListSelectionListener() {
            public void valueChanged( ListSelectionEvent e )
            {
               Object o = siteChooser.getSelectedValue();
               URL newDocument = (URL) internetsitesi.get( o );
               AppletContext browser = getAppletContext();
               browser.showDocument( newDocument );
            }
         }
      );
      c.add( new JScrollPane( siteChooser ),
             BorderLayout.CENTER );
   }

   private void getinternetsitesiFromHTMLParameters()
   {
      //HTML dökümanındaki applet parametrelerini incele ve site isimlerini oku
      String baslik, yer;
      URL url;
      int counter = 0;

      while ( true ) {
         baslik = getParameter( "baslik : " + counter );

         if ( baslik != null ) {
            yer = getParameter( "adres :" + counter );
            
            try {
               url = new URL( yer );
               internetsitesi.put( baslik, url );
               siteIsimleri.addElement( baslik );
            }
            catch ( MalformedURLException e ) {
               e.printStackTrace();
            }
         }
         else
            break;

         ++counter;  
      }
   }
}

/**************************************************************************
 * (C) Copyright 1999 by Deitel & Associates, Inc. and Prentice Hall.     *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/
