/* 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 GetSet 

7.   extends Applet 

8.   implements ActionListener 

9.

10.   HashSet setlet ; 

11. //HashSet<String> setlet ; 

12.   public void actionPerformed ( ActionEvent ev ) 

13.   { 

14.     if ( setlet == null

15.       setlet = new HashSet( 30 ) ; 

16. //    setlet = new HashSet<String> ( 30 ) ; 

17.     setlet.add ( "car54" ); 

18.     setlet.add ( "radiatingphone" ); 

19.     setlet.add ( "settostungun" ); 

20.     boolean addedsuccesfully = setlet.add ( "car54" ); 

21.  

22.     if ( ! setlet.contains ( "grandpiano" )  ) 

23.     { 

24.       ta.append ( "No grand in the set\n\n" ) ; 

25.     } 

26.     Iterator iter = setlet.iterator(); 

27. //  Iterator<String> iter = setlet.iterator( ); 

28.     String s = null

29.     while ( iter.hasNext()  ) 

30.     { 

31.       s = (String) iter.next(); 

32.       ta.append ( s + "\n\n" ) ; 

33.       if ( s.equalsIgnoreCase ( "radiatingphone" ) ) 

34.         iter.remove() ; 

35.     } 

36.     ta.append ( "Set contains "

37.               setlet.size() + " elements.\n"  ); 

38.     setlet.clear(); 

39.   } 

40.   public void init() 

41.   { 

42.     butt.addActionListener ( this ) ; 

43.     add ( butt ) ; 

44.     add ( ta ) ; 

45.     setBackground ( Color.cyan ) ; 

46.   } 

47.    TextArea ta = new TextArea ( 10, 30 ) ; 

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

49.