/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import java.awt.event.* ; 

2. import java.awt.* ; 

3. import java.applet.*; 

4. import java.util.* ; 

5.  

6. public class Mapped 

7.   extends Applet 

8.   implements ActionListener 

9.

10.   HashMap maplet ; 

11. //  HashMap<String, Integer> maplet ; 

12.   public void actionPerformed ( ActionEvent ev ) 

13.   { 

14.     if ( maplet == null

15.       maplet = new HashMap ( 50 ) ; 

16. //      maplet = new HashMap<String, Integer> ( 50 ) ; 

17.     maplet.put ( "LA", new Integer(535) ); 

18.     maplet.put ( "Amsterdam", new Integer(72) ); 

19.     maplet.put ( "Caracas", new Integer(72) ); 

20.     maplet.put ( "Moscow", new Integer(884) ); 

21.  

22.     Integer nr = null

23.  

24.     if ( maplet.containsKey ( "Amsterdam" )  ) 

25.     { 

26.       nr = (Integer) maplet.get ( "─msterdam" ) ; 

27.       maplet.remove ( "Amsterdam" ) ; 

28.     } 

29.     Set keys = maplet.keySet() ; 

30. //    Set<String> keys = maplet.keySet() ; 

31.     Iterator iter = keys.iterator(); 

32. //    Iterator<String> iter = keys.iterator(); 

33.     String k = ""

34.     while ( iter.hasNext()  ) 

35.     { 

36.       k = (String) iter.next(); 

37.       ta.append ( k + "\n" ) ; 

38.       if ( k.equalsIgnoreCase ( "Moscow" ) ) 

39.         iter.remove() ; 

40.     } 

41.     ta.append ( "Map contains "

42.               maplet.size() + " pairs\n"  ); 

43.     maplet.clear(); 

44.   } 

45.   public void init() 

46.   { 

47.     butt.addActionListener ( this ) ; 

48.     add ( butt ) ; 

49.     add ( ta ) ; 

50.     setBackground ( Color.yellow ) ; 

51.   } 

52.   TextArea ta = new TextArea ( 7, 30 ) ; 

53.   Button butt = new Button ( "Do it" ) ; 

54.