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 sitesi 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 dokomanindaki 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;  
      }
   }
}
