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

5. public class StrBuf 

6.   extends Applet 

7.   implements ActionListener 

8.

9.   StringBuffer  strbuf ;    

10.  

11.   public void actionPerformed( ActionEvent ev ) 

12.   { 

13.     strbuf.insert ( 3, '+' ) ;   

14.  

15.     char firstchar = strbuf.charAt ( 0 ) ;  

16.     strbuf.append ( firstchar ) ;   

17.  

18.     String  str =  strbuf.toString ( ) ;  

19.  

20.     ta.append ( str  + '\n'  ) ; 

21.   } 

22.  

23.   public void init() 

24.   { 

25.     strbuf.append ( "ABC12" ) ;   

26.     strbuf.append ( '3' ) ;      

27.  

28.     bt.addActionListener ( this ) ; 

29.     setBackground ( Color.lightGray ) ; 

30.  

31.     add ( ta ) ; 

32.     add ( bt ) ; 

33.     validate () ; 

34.   } 

35.  

36.   public StrBuf () 

37.   { 

38.     strbuf = new StringBuffer ( 50 ) ; 

39.  

40.     bt = new Button ( "Doowit" ) ; 

41.     ta = new TextArea (  12, 50 ) ; 

42.   } 

43.  

44.   TextArea ta ; 

45.   Button bt ; 

46.

47. /*======================= 

48.   append ( char [ ]  ) 

49.   append ( double

50.   append ( int

51.  

52.   charAt ( int pos ) 

53.  

54.   insert ( int pos, String

55.  

56.   reverse ( ) 

57.  

58.   setCharAt ( int pos , char

59.  

60.   setLength ( int

61.       cut it short or give it more room. 

62.  

63. As of 1.2

64.   delete ( int from , int to ) 

65.   replace ( int from , int to, String

66. */